4
When searching for a certain occurrence in a string with Regex without the flag g
(of global), the result comes, in addition to the array with the occurrence found, other properties such as index
, input
and groups
:
var string = "abc";
var re = string.match(/b/);
console.log("Ocorrência:", re);
console.log("Index:", re.index);
console.log("Input:", re.input);
console.log("Groups:", re.groups);
My question is: what is and what is this property for groups
?
I thought it would be some captured group, but when I put the b
within parentheses to create a group, even though the property groups
returns undefined
:
var string = "abc";
var re = string.match(/(b)/);
console.log("Ocorrência:", re);
console.log("Index:", re.index);
console.log("Input:", re.input);
console.log("Groups:", re.groups);
Cool guy! I didn’t know this r... thanks anyway!
– Sam
@Sam The name of the property confuses, right? The first time I saw it, I thought she had all the groups...
– hkotsubo
Yes, I found it too...
– Sam
Good answer!! I think I could add that this group feature in regular expressions is from a newer version of Javascript. If I’m not mistaken, ES2018!
– Luiz Felipe
@Luizfelipe I was looking for a link with the exact version. Reply updated, thank you! :-)
– hkotsubo