RegExp {X,Y} Quantifier, matches any string that contains a sequence of X to Y n's. X and Y must be a number - Javascript RegExp

Javascript examples for RegExp:Quantifier

Description

The n{X,Y} quantifier matches any string that contains a sequence of X to Y n's. X and Y must be a number.

The following code shows how to Do a global search for a substring that contains a sequence of three to four digits:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w w  w .  ja  v a2s. c o m*/
    var str = "1233 12333 100, 1000 or 10000?";
    var patt1 = /\d{3,4}/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials