RegExp * Quantifier, matches any string that contains zero or more occurrences - Javascript RegExp

Javascript examples for RegExp:Quantifier

Description

The n* quantifier matches any string that contains zero or more occurrences of n.

Do a global search for an "l", followed by zero or more "o" characters:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//w  w w .  j a  v a2 s. c  o m
    var str = "1, 100 or 1000?";
    var patt1 = /10*/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials