Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade For Teachers Spaces Get Certified Upgrade For Teachers Spaces
   ❮     
     ❯   

Basic JavaScript

JS TutorialJS SyntaxJS VariablesJS OperatorsJS If ConditionsJS LoopsJS StringsJS NumbersJS FunctionsJS ObjectsJS DatesJS ArraysJS Typed ArraysJS SetsJS MapsJS MathJS RegExpJS Data TypesJS ErrorsJS EventsJS ProgrammingJS ReferencesJS Versions

JS Advanced

JS FunctionsJS ObjectsJS ClassesJS IterationsJS AsynchronousJS ModulesJS Meta & ProxyJS HTML DOMJS WindowsJS Web APIJS AJAXJS JSONJS jQueryJS GraphicsJS ExamplesJS Reference


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

CodeDescription
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 onex.

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 ofx.

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} matchesn occurences ofx.

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 fromn tom occurences ofx.

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,} matchesn or more occurences ofx.

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 ExpressionSearch andReplace 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 ourterms of use,cookies andprivacy policy.

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


[8]ページ先頭

©2009-2025 Movatter.jp