How do you access the matched groups in a JavaScript regular expression? How do you access the matched groups in a JavaScript regular expression? javascript javascript

How do you access the matched groups in a JavaScript regular expression?


You can access capturing groups like this:

var myString = "something format_abc";var myRegexp = /(?:^|\s)format_(.*?)(?:\s|$)/g;var myRegexp = new RegExp("(?:^|\s)format_(.*?)(?:\s|$)", "g");var match = myRegexp.exec(myString);console.log(match[1]); // abc