Putting parenthesis "()" around part of a regular expression is a way to determine it's value and take appropriate action. For example, in the text based music notation system abc, the following examines a note:
// <stc><-- accidental----><--note--><octav><num>< / ><dem><trail>
var anote = /(\.?)(\^{0,2}|=?|_{0,2})([A-Ga-g])([',]*)(\d*)(\/*)(\d*)([- ]*)/;
Only the upper or lower case letters "a-g" have to be there-- a stacatto dot, an accidental, octave change, duration, and/or trailing dash or space are all optional. This is an example of some code that follows a match command:
for (var i =0; i<result[4].length; i++) {
var achar = result[4].charCodeAt(i); // alert("achar = " + achar);
if (achar == 44) {pos -= 7;} // Comma down
if (achar == 39) {pos += 7;} } //Apostrophe, up
HTH