Reputation: 2534
I want to look for a specific function call statement and if found need to extract the arguments using javascript regex.
for ex: say obj.methodname(arg1,arg2)
or obj.methodname(arg1, arg2)
notice the space between the arguments which is possible and the number of arguments is also not fixed.
I tried various regex for the same from SO itself but couldn't get it to work
one of them is /obj.methodname([\w,]*)/.exec(text)
but not getting the arguments, only getting methodname
please help
Upvotes: 1
Views: 1969
Reputation: 26667
Something like,
> "obj.methodname(arg1,arg2)".match(/obj.methodname\((.*)\)/)[1].split(",")
< ["arg1", "arg2"]
Further, you can trim
the values to get rid of the spaces
> ["arg1", " arg2"].map(function(value){ return value.trim() })
< ["arg1", "arg2"]
Upvotes: 3