JavaScript RegExp {X,Y}Quantifier

RegExp 对象参考手册JavaScript RegExp Object


Definition and Usage

n{X,Y} Quantifier matches strings containing at least X and at most Ynof the sequence of strings

XandYMust be a number.

Syntax

new RegExp("n{X,Y}")

Or a simpler way:

/n{X,Y}/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the {X,Y} quantifier.


Example

Example

Perform a global search for substrings containing sequences of three or four digits:

var str="100, 1000 or 10000?"; var patt1=/\d{3,4}/g;

Belowmarkedtext shows the positions where the expression gets a match:

100, 1000 or 10000?

Try it Yourself »


RegExp 对象参考手册JavaScript RegExp Object

Other Extensions