简体   繁体   English

如果匹配,则提取带括号的字符串(正则表达式)

[英]Extract string with in parenthesis if matched (regex)

The string could be as follows.该字符串可能如下所示。

poptype in ('01')
and (a0='169'or a1='169'or a2='169'or a3='169'or a4='169'or a5='169'or a6='169'or a7='169'or a8='169'or a9='169')  
and (sku in ('67798240','67724312','67724313','67460442','67629434'))  
and (geo_code in ('D01365','D01353','D01354','D01356','D01364','D01357','D01555'))

The result should be as follows:结果应如下所示:

Output required:所需输出:

(a0='169'or a1='169'or a2='169'or a3='169'or a4='169'or a5='169'or a6='169'or a7='169'or a8='169'or a9='169')

If "a0" or "a9" exists in a string, I want to match whole wordings within first parent parenthesis.如果字符串中存在“a0”或“a9”,我想匹配第一个括号内的整个措辞。

This should do it:这应该这样做:

\(.*(?:a0|a9).*\)

Check out at: https://regex101.com/r/SWtZh4/1 Basically it matches everything within the brackets if a0 or a9 have been found in it.查看: https ://regex101.com/r/SWtZh4/1 如果在括号中找到 a0 或 a9,它基本上匹配括号内的所有内容。

If "a0" or "a9" exists in a string, I want to match whole wordings within first parent parenthesis.如果字符串中存在“a0”或“a9”,我想匹配第一个括号内的整个措辞。

(\\([^\\(]+(a0|a9)[^\\)]+\\))

That should basically do what you want.这基本上应该做你想做的。

Looking for a opening brace, followed by any number of non-opening-brace characters, then a0 or a9, and then "mirrored" for the closing brace on the other end.寻找左大括号,后跟任意数量的非左大括号字符,然后是 a0 或 a9,然后“镜像”另一端的右大括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM