Flash cards
Review the key moves
What is the main idea behind RegExp Quantifiers?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
// ___ at least one zeroPut the learning moves in the order that makes the concept easiest to apply.
Quantifiers define the numbers of characters or expressions to match.
// Match at least one zero
const pattern = /0+/;JavaScript RexExp Quantifiers
| 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 |
RegExp + Quantifier
x + matches matches at least one x .
Example
let text = "Hellooo World! Hello ExampleSite!";
const pattern = /lo+/g;
let result = text.match(pattern);RegExp * Quantifier
x * matches zero or more occurrences of x .
Example
let text = "Hellooo World! Hello ExampleSite!";
const pattern = /lo*/g;
let result = text.match(pattern);RegExp ? Quantifier
x ? matches zero or one occurrences of x.
Example
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 .
Runnable example
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 .
Runnable example
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 .
Runnable example
let text = "100, 1000 or 10000?";
let pattern = /\d{3,}/g;
let result = text.match(pattern);Regular Expression Methods
Regular Expression Search and Replace can be done with different methods.
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 |
See Also
JavaScript RegExp Flags
JavaScript RegExp Character Classes
JavaScript RegExp Meta Characters
JavaScript RegExp Assertions
JavaScript RegExp Patterns
JavaScript RegExp Objects
JavaScript RegExp Methods