简体   繁体   中英

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.

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.

If "a0" or "a9" exists in a string, I want to match whole wordings within first parent parenthesis.

(\\([^\\(]+(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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