Reputation: 97
I'm trying to get string from other string having multiple layers of brackets, but I have problem with making good regular expression. How looks desired expression?
I tried expression \((.*?)\)
but the expression is getting first bracket which see...
For example, when I have input string
(many things including things in inner brackets (like this))
I expect group(1)
having value
many things including things in inner brackets (like this)
but actual value of group(1)
is many things including things in inner brackets (like this
Upvotes: 0
Views: 35
Reputation: 18357
You need to get rid of that non-greedy quantifier so your regex can match exhaustively and only stop at last )
instead of the earlier one which is happening because of your non-greedy expression. Just change your regex from \((.*?)\)
to \((.*)\)
Upvotes: 2