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 parens that do not, themselves, contain parens.
Use this expression:
/\(([^()]+)\)/g
e.g:
function(){ var mts = "something/([0-9])/([a-z])".match(/\(([^()]+)\)/g ); alert(mts[0]); alert(mts[1]);}
If s is your string:
s.replace(/^[^(]*\(/, "") // trim everything before first parenthesis .replace(/\)[^(]*$/, "") // trim everything after last parenthesis .split(/\)[^(]*\(/); // split between parenthesis