Find More Than the First Match # 21

So far, we have only been able to extract or search a pattern once with the following code...

let testStr = "Repeat, Repeat, Repeat"; let ourRegex = /Repeat/; testStr.match(ourRegex);

Here the match would return ["Repeat"].

To search or extract a pattern more than once, you can use the g flag.

let repeatRegex = /Repeat/g; testStr.match(repeatRegex);

And here match returns the value ["Repeat", "Repeat", "Repeat"]


Post a Comment

Previous Post Next Post