Regular Expressions: Find More Than the First Match 1

Regular Expressions: Find More Than the First Match

let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /Twinkle/gi; // Change this line
let result = twinkleStar.match(starRegex); // Change this line

Here is what the above code is Doing:
1. The twinkleStar variable contains the string value of “Twinkle, twinkle, little star”.
2. The starRegex is a regular expression that looks for the string “Twinkle” in any case.
3. The match() method looks for the regular expression inside the string twinkleStar and returns the result.

Similar Posts