简体   繁体   中英

Regex - match text in quotes inside parenthesis

I have a regular expression that will match quoted text '.*?' but how can I apply this to quoted text only if its encased in parens. For example:

('want this', 'want this', dont want)
 'dont want'

If you are sure the parentheses always come in open/close pairs, you could use this regular expression:

'[^']*'(?=[^(']*('[^']*'[^'(]*)*\))

It requires that a matching quoted text is followed by a closing parenthesis (not itself in quotes) before any opening one. Also the number of quotes that appear after the match and before the closing parenthesis must be even in number (open/close)

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