In String.prototype.match (), the captured groups are not returned.
If you need capture groups, use RegExp.prototype.exec (). It will return an array, the first element will be a complete match, and the following elements will capture capture groups.
var regexObj = /\s{1,}(male)\.$/gi; console.log(regexObj.exec('A girl is a female, and a boy is a male.'));
It will display:
[' male.', 'male'] // Second element is your capture group
omerts
source share