How to find all instances of a pattern in JavaScript ?

To find out out all the instances of a pattern in JavaScript , you can use the regular expression as showb below.

How to find all instances of a pattern in JavaScript ?

<script type="text/javascript">
    var inputStr = "abundantcode is a programing website with abundantcode snippets";
    var Searchpattern = /abundant\w*e/g;
    var item;
    var output = "";
    while ((item = Searchpattern.exec(inputStr)) != null) {
        output += "" + item.index + " is found at " + item[0] + "\n";
    }
    document.write(output);
</script>