<!DOCTYPE html>
<html>
<body>

<p>Click the button to do a global search for any of the specified alternatives (red|green).</p>

<button onclick="myFunction()">Try it</button>

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

<script>
function myFunction() {
    var str = "re, green, red, green, gren, gr, blue, yellow";
    var patt1 = /(red|green)/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>