0

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

Community
  • 1
  • 1
Nexus Fred
  • 63
  • 1
  • 10

1 Answers1

2

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).

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125