Reputation: 2391
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
Upvotes: 3
Views: 117
Reputation: 626960
You may use
\([^()]*(?:(?R)[^()]*)+\)
Settings:
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.Upvotes: 2