Reputation: 1403
Suppose i have a string,
str = "Date()+Abs(9)Day()+45"
I want an array that contains:
arr[0]=Date()
arr[1]=Abs(9)
arr[2]=Day()
My current parser:
var temp = str.match(/\w+(\w+)/)
Please help
Upvotes: 0
Views: 86
Reputation: 48600
This is a pretty easy expression.
/ -- START expression
\w+ -- One or more alpha-numeric (plus '_')
\( -- Literal opening parenthesis
[\w/-]* -- Zero or more alpha-numeric (plus '_', '/', and '-')
\) -- Literal closing parenthesis
/g -- END expression; Global match
var str = "Date(20/04/98)+Abs(-9)Day(20/04/98)+45"
var arr = str.match(/\w+\([\w/-]*\)/g);
console.log(JSON.stringify(arr, null, 2));
// arr[0] = Date(20/04/98)
// arr[1] = Abs(-9)
// arr[2] = Day(20/04/98)
Upvotes: 7