RegExp Quantifiers
RegExp Quantifiers
Quantifiers define the numbers of characters or expressions to match.
x+, x*, x?, x{n}, x{n,}, x{n,m}
The + Quantifier
x+ matches matches at least one x.
Example
A global search for at least one "o":
let text = "Hellooo World! Hello W3Schools!";
let result = text.match(/o+/g);
The * Quantifier
x* matches zero or more occurrences of x.
Example
A global search for an "l", followed by zero or more "o" characters:
let text = "Hellooo World! Hello W3Schools!";
let result = text.match(/lo*/g);
The n? Quantifier
x? matches zero or one occurrences of x.
Example
A global search for "1", followed by zero or more "0" characters:
let text = "1, 100 or 1000?";
let result = text.match(/10?/g);
Full Quantifiers Reference
Revised July 2025
Code | Description |
---|---|
x+ | 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,} | Matches n or more occurences of x |
Regular Expression Methods
Regular Expression Search and Replace can be done with different methods.
These are the most common:
String Methods
Method | Description |
---|---|
match(regex) | Returns an Array of results |
matchAll(regex) | Returns an Iterator of results |
replace(regex) | Returns a new String |
replaceAll(regex) | Returns a new String |
search(regex) | Returns the index of the first match |
split(regex) | Returns an Array of results |
RegExp Methods
Method | Description |
---|---|
regex.exec() | Returns an Iterator of results |
regex.test() | Returns true or false |