My regular expression is not working as expected


I’m using the capturing groups parentheses so it this regex only matches against visitedcount=numbers. I want str.match(regex) to return visitedcount= and 2. However, it returns one array which is just visitedcount=2. Am I misunderstanding something?

1 Like

String#match returns whole match. To get capturing groups, you should use RegExp#exec method

Your code will be:

let match = regExp.exec(str);
// do match[n] for nth capturing group
1 Like

Thanks! This’ll work perfectly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.