Let's look at a repetition based metacharacter, plus (+
). It checks if the previous character (from the position of +
) in the string appears one or more times from that position.
xxxxxxxxxx
13
// Adding a function to wrap the existing code
function findMatch() {
let s = "Zoooooootopia";
let pattern = /Zo+topia/;
if (pattern.test(s)) {
console.log("Found a match!");
} else {
console.log("Did not find a match.");
}
}
// Driver code to execute the function
findMatch();
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment