I am trying to extract the function arguments from my string s
var s = "function (a, b, c) { return \'hello\'; }";
var re = /^function[^\(]*\(\W*(?:(\w+)[,\s)]*)+\)/g;
console.log( re.exec(s) );
/*
[ 'function (a, b, c)',
'c',
index: 0,
input: 'function (a, b, c) { return \'hello\'; }' ]
*/
The problem
It is only capturing c
.
Desired output
/*
[ 'function (a, b, c)',
'a',
'b',
'c',
index: 0,
input: 'function (a, b, c) { return \'hello\'; }' ]
*/
Disclaimer
This code is used in a module and must be accomplished with a single regular expression. Other techniques I've seen on StackOverflow will not work.