I have this regex...
/user/([A-Za-z0-9]*)
Which is matched to this input string...
/user/me
Which brings this result in console...
['/user/me', 'me', index: 0, input: '/user/me']
Also see this example...
Regex: /user/([A-Za-z0-9]*)/([A-Za-z0-9]*)
Input: /user/me/you
Result: ['/user/me/you', 'me', 'you', index: 0, input: '/user/me/you']
First result just returns me but second returns me and you, is there a built-in function in node.js that will extract these occurrences or I would need to loop through this array with conditions?
Just use Array.slice
:
results=mystring.match(myregex).slice(1);
What version of Node are you using? The result of matching /user/me/you
seems unreasonable. Anyway, I run code below on Node.js 0.8.4
> r = /\/user\/([A-Za-z0-9]*)/
/\/user\/([A-Za-z0-9]*)/
> r.exec('/user/me')
[ '/user/me',
'me',
index: 0,
input: '/user/me' ]
> r.exec('/user/me/you')
[ '/user/me',
'me',
index: 0,
input: '/user/me/you' ]