Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用正则表达式拆分复杂字符串_Regex_Oracle - Fatal编程技术网

Regex 使用正则表达式拆分复杂字符串

Regex 使用正则表达式拆分复杂字符串,regex,oracle,Regex,Oracle,我有这个字符串,需要使用OracleRegexp\u substr 绳子就像 "123456","4,5,6","Hi This is "Sample" String",12345,022222 我需要把这根绳子分成两半 "123456" "4,5,6" "Hi This is "Sample" String" 12345 022222 我尝试使用以下逻辑试图提取字符串,使用,作为分隔符,后跟,作为分隔符,但当我使用REGEXP(字符串,“*”,”1,1)时,它会将字符串转换为 "12345

我有这个字符串,需要使用Oracle
Regexp\u substr

绳子就像

"123456","4,5,6","Hi This is "Sample" String",12345,022222
我需要把这根绳子分成两半

"123456"
"4,5,6"
"Hi This is "Sample" String"
12345
022222
我尝试使用以下逻辑试图提取字符串,使用
作为分隔符,后跟
作为分隔符,但当我使用
REGEXP(字符串,“*”,”1,1)
时,它会将字符串转换为

"123456","4,5,6","Hi This is "Sample" String",
因为REGEXP是贪婪的表达式


如何获得最终结果?

好吧,您必须访问捕获组2才能获得第一个匹配项(或者如果存在引号,则只需去掉引号):


(?:^(“*)(.+?)\1(?=,)|(?:(?此选项适用于您的示例:


(“+?”(?=,)|\w+/code>
“*?”
应该可以解决这个贪婪的特殊问题。“?”使它不情愿地匹配。仍然不能完全满足你的要求,但不太确定嵌套引号的用法,或者不。也许
(“*?”[^“]*?)(,|$)
太好了!谢谢你的朋友
(?:^("*)(.+?)\1(?=,))|(?:(?<=,").+?(?=",))|(?:(?<=,)[^"]+?(?=,|$))