javascript - Extracting arguments using regular expressions -


i'm trying use regex extract arguments function definition array. example

func(a) -> ['a'] func(a,b) -> ['a','b'] func(a, b) -> ['a','b'] 

the regex below correctly matches arguments block

/\((?:(\w+),?\s*)+\)/ 

however, last matched capturing group returned i.e. results are:

func(a) -> ['a'] func(a,b) -> ['b'] func(a,b,c) -> ['c'] 

this seems useful pattern capturing part of repeating unit. there way correctly achieve expected result?

my saved regexr session can found here

the regex /\((\w+(?:,\s?\w+)?)\)/ return a, b func(a, b), a,b,c func(a,b,c)

hopefully wanted, depending on language you're doing for, can split them each , put them array indexing later.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -