Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find double parenthesis using Notepad++

I am trying to find sentences that has opening and closing parenthesis within another one, like (text (more)) . I tried something like the following \([^\)].*?\( - \(.*\( - ((?:\([^]]*\))+) to match at least the first two (( but it's not right, and I think it would be better to match something like ((.*)) with a lazy quantifier, and it should work with anything in the text between the (()), even if it is divided between lines like in html codes. etc.

Example text:

know that I can (negate) group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow (that I can negate) group of ((chars aknow that)) I can negate group of chars aknow that I can negate (group (of chars) (aknow) that) I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars a know that I can negate ((group of chars a know that I can negate)) group of chars a

aknow that I can negate group of (chars aknow that I can negat#e g[roup] of chars

aknow that aknow that I can negate group of (chars aknow)) that I can negate group of chars aknow that

like image 315
Mike Avatar asked Nov 24 '25 08:11

Mike


1 Answers

You may use

\([^()]*(?:(?R)[^()]*)+\)

Settings:

enter image description here

Details

  • \( - a ( char
  • [^()]* - 0+ chars other than ( and )
  • (?:(?R)[^()]*)+ - 1 or more repetitions of
    • (?R) - the whole pattern is recursed
    • [^()]* - 0+ chars other than ( and )
  • \) - a ) char.

enter image description here

like image 71
Wiktor Stribiżew Avatar answered Nov 26 '25 22:11

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!