I\'m looking for a regular expression (**) that will match an unknown number of nested functions. So
expression
function(expression)
function(function(expres
This isn't recursive, but it does the trick.
var target = "function(function(function(expression)))";
var pattern = /\s*([a-zA-Z_]\w*[(](\s*[a-zA-Z_]\w*[(]|[^()]+[)]|[)])+[)])/;
var matches = target.match(pattern);
var target= matches[1];
\s* // 0+ white space characters
( // Capture group for what you want
[a-zA-Z_] // 1 letter/underscore
\w* // 0+ word characters (alpha-numeric/underscore)
[(] // left parenthesis
( // PIECES:
\s* // 0+ white space characters
[a-zA-Z_] // 1 letter/underscore
\w* // 0+ word characters (alpha-numeric/underscore)
[(] // left parenthesis
| // OR
[^()]+ // 1+ non-parenthesis characters
[)] // right parenthesis
| // OR
[)] // right parenthesis
)+ // 1+ of these PIECES
[)] // right parenthesis
)