RegEx to match stuff between parentheses

You need to make your regex pattern ‘non-greedy’ by adding a ? after the .+

By default, * and + are greedy in that they will match as long a string of chars as possible, ignoring any matches that might occur within the string.

Non-greedy makes the pattern only match the shortest possible match.

See Watch Out for The Greediness! for a better explanation.

Or alternately, change your regex to

\(([^\)]+)\)

which will match any grouping of parentheses that do not, themselves, contain parentheses.

Leave a Comment