RegExp g Modifier - Javascript RegExp

Javascript examples for RegExp:Modifier

Description

The g modifier does a global match to find all matches rather than stopping after the first match.

To perform a global, case-insensitive search, use this modifier together with the "i" modifier.

The following code shows how to Click the button to check whether or not the "g" modifier is set.

The marked text below shows where the expression gets a match:

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   ww  w.j av a 2  s . c  o m*/
    var str = "Visit book2s java2s.com!";
    var patt1 = /book2s/g;
    var res = patt1.global;
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials