Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

JavaScript Basic

JS HOME JS Introduction JS Where To JS Output JS Syntax JS Statements JS Comments JS Variables JS Data Types JS Let JS Const JS Operators JS Arithmetic JS Assignment JS Functions JS Objects JS Events JS Strings JS String Templates JS Numbers JS Arrays JS Dates JS Math JS Booleans JS Comparisons JS Logical JS If Else JS Switch JS Loops JS Break JS Continue JS Errors JS Scope JS Code Blocks JS UTF-8 Characters

JS Advanced

JS Versions JS Statements JS Data Types JS String Methods JS Number Methods JS Date Formats JS Array Methods JS Functions JS Objects JS Classes JS Sets JS Maps JS Loops JS RegExp JS Callbacks JS Strict Mode JS DOM JS Window JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples

JS References

JavaScript Objects


RegExp Quantifiers

RegExp Quantifiers

Quantifiers define the numbers of characters or expressions to match.

// Match at least one zero
const pattern = /0+/;

JavaScript RexExp Quantifiers

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

RegExp + Quantifier

x+ matches matches at least one x.

Example

A global search for at least one "o":

let text = "Hellooo World! Hello W3Schools!";
const pattern = /lo+/g;

let result = text.match(pattern);

Try it Yourself »


RegExp * 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!";
const pattern = /lo*/g;

let result = text.match(pattern);

Try it Yourself »


RegExp ? 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?";
const pattern = /10?/g;

let result = text.match(pattern);

Try it Yourself »



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);
Try it Yourself »

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);
Try it Yourself »

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);
Try it Yourself »

Regular Expression Methods

Regular Expression Search and Replace can be done with different methods.

These are the most common:

String Methods

MethodDescription
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

MethodDescription
regex.exec() Returns an Iterator of results
regex.test() Returns true or false


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.