使用regexp_substr选择逗号之间的单词(不包括双引号) [英] Select words between commas (excluding double quotations) using regexp_substr

查看:220
本文介绍了使用regexp_substr选择逗号之间的单词(不包括双引号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从逗号分隔的列表中返回一个字符串列表.但是,我仍然想返回字符串中出现在双引号之间的逗号.

I'm attempting to return a list of strings from a comma delimited list. However, I still want to return commas in strings where they appear between double quotation marks.

这是我当前的声明:

SELECT 
  regexp_substr('one,two,"three, four five",six,"seven, eight, nine"', 
                '(.*?,){'||(n-1)||'}([^,]*)', 1, 1, '', 2) token
FROM (SELECT LEVEL n FROM dual CONNECT BY LEVEL <= 10);

这将返回:

one
two
"three
four five"
six
"seven
eight
nine"

但是我需要返回:

one
two
three, four, five
six
seven, eight, nine

我的正则表达式生锈了.有没有一种干净的方法来修改我的正则表达式来实现这一目标?

My regex is rusty. Is there a clean way to modify my regex to achieve this?

谢谢!

推荐答案

尝试一下:

'^("[^"]*",|[^",]*,){'||(n-1)||'}("[^"]*"|[^",]*)', 1, 1, '', 2

或更简单的版本:

'(^|,)("[^"]*"|[^",]*)', 1, n, '', 2

或者如果不需要引号-将其包装到:

or if quotes aren't desired - wrap it into:

regexp_replace( ..., '"', '')

这篇关于使用regexp_substr选择逗号之间的单词(不包括双引号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆