I’m trying to parse apart a string like this with javascript:
var mystr = "param1('stringValue'), param2(IntegerValue IntegerValue)";
Where in the end I need to get each of the param names (param1 and param2) and values (either one string value, or two integer values).
However, the original string could have any number of parameters, such as:
"param1('stringValue')"
"param1('stringValue'), param2(IntegerValue IntegerValue), param2(IntegerValue IntegerValue)"
Requirements:
- Between each parameter is a comma, and values are within the parentheses.
- Within the parentheses could either be one string value, or two integers with a space in between.
- There could be any number of parameters (but at least 1)
Strings should not have
'symbols in them. If you want completely foolproof solution, you need to abandon regexs and use some parser.Parsing escaped string would be possible with something like
[^']|(<?\\(?:\\\\)*)', but regexes in js doesn’t support look-behinds and AFAIR variable-length look-behinds are not supported at all.