Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

RegExp {X} quantifier

JavaScript RegExp {X} quantifier

RegExp Object Reference The JavaScript RegExp object


Definition and Usage

n{XThe {X} quantifier matches a string containing exactly X n occurrences of the preceding sequence.

X Must be a number.

Syntax

new RegExp("

n

{

X

}")

Or a simpler way:

/

n

{

X

}/


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the {X} quantifier.


Example

Example

Perform a global search for substrings containing a sequence of four digits:

var str="100, 1000 or 10000?";

var patt1=/d{4}/g;

Match four digits:

var

str

=

"

100, 1000 or 10000?

"

;

var

patt1

=/\

d

{

4

}

/

g

;

Try it »


RegExp Object Reference The JavaScript RegExp object