RegExp ^ Quantifier, matches any string at the beginning of it. - Javascript RegExp

Javascript examples for RegExp:Quantifier

Description

The ^n quantifier matches any string at the beginning of it.

Use the n$ quantifier to match any string with n at the END of it.

The following code shows how to Do a global search for "Is" at the beginning of a string:

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  .  j  a  v  a  2s  . c  om*/
    var str = "Is this his";
    var patt1 = /^Is/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials