Reputation: 63
I try to build a Regex to select all text between parentheses with a specific text like as target.
Something like (*TARGET*)
. I found this regex here : Regular Expression to get a string between parentheses in Javascript But (2014) and (Format) are select also.
\(([^)]+)\)
-Sample
Number 473 (2014) (Format)(not_wanted-text1 TARGET not-wanted_text2).xxx
or
Number 473 (2014) (Format)(TARGET not-wanted_text2).xxx
or
Number 473 (2014) (Format)(not-wanted_text2TARGET).xxx
-Expected result
Number 473 (2014) (Format).xxx
Thanks
Upvotes: 0
Views: 899
Reputation: 89639
You only have to include the target string surrounded by character classes that exclude the closing parenthesis:
\(([^)]*TARGET[^)]*)\)
If you only need to replace the match, you don't need the capture group (you can remove it).
Upvotes: 2