Loading lesson path
Overview
Quantifiers define the numbers of characters or expressions to match.
// Match at least one zero const pattern = /0+/;Matches at least one x x* Matches zero or more occurrences of x x?
Matches zero or one occurrences of x x{n}
Matches n occurences of x x{n,m}
Matches from n to m occurences of x x{n,}Formula
RegExp + Quantifier x+ matches matches at least one x.
A global search for at least one "o":
let text = "Hellooo World! Hello W3Schools!";
const pattern = /lo+/g;
let result = text.match(pattern);Formula
RegExp * Quantifier xA global search for an "l", followed by zero or more "o" characters:
let text = "Hellooo World! Hello W3Schools!";
const pattern = /lo*/g;
let result = text.match(pattern);? matches zero or one occurrences of x.
A global search for "1", followed by zero or one "0" characters:
let text = "1, 100 or 1000?";
const pattern = /10?/g;
let result = text.match(pattern);
RegExp {n} Quantifier x
{n
}matches n occurences of x. A global search for a string that contains a sequence of four digits:
let text = "100, 1000 or 10000?";
let pattern = /\d{4}/g;
let result = text.match(pattern);
RegExp {n,m} Quantifier x
{n, m
}matches from n to m occurences of x. A global search for a substring that contains a sequence of three to four digits:
let text = "100, 1000 or 10000?";
let pattern = /\d{3,4}/g;
let result = text.match(pattern);
RegExp {n,} Quantifier x
{
n,}matches n or more occurences of x. A global search for a sequence of at least three digits:
let text = "100, 1000 or 10000?";
let pattern = /\d{3,}/g;
let result = text.match(pattern);Replace can be done with different methods.
regex )
regex )
regex )
regex )
regex ) Returns the index of the first match split( regex )
Description regex.exec() Returns an Iterator of results regex.test()