Reputation: 592
My matching Regex for capturing all words within parenthesis (including the parenthesis) is
\([\w\s,.]+\)
I need to ignore the capture when (City of Toronto) appears
Lorem ipsum dolor sit amet, (Capture This) consectetur adipiscing elit. Integer nulla nisi, viverra ut eros vitae, bibendum elementum quam (City of Toronto). Morbi quam libero, sollicitudin et sapien et, lacinia (Capture this as well) euismod tellus.
I would want the matches to be #1- (Capture This) and #2- (Capture this as well)
Essentially I'd like to create a white list of phrases to avoid but if they don't match, then capture the text.
Upvotes: 0
Views: 38
Reputation: 163277
Maybe you could use a negative lookahead to assert that what follows is not (City of Toronto)
(?!\(City of Toronto\))\([\w\s,.]+\)
You can use alternation |
to add multiple options.
The slightly faster version from @ctwheels with the alternation:
\((?!City of Toronto|Hong Kong|United Kingdom\))[\w\s,.]+\)
Upvotes: 3