JS RegExp Object

JavaScript RegExp Object

The Javascript RegExp object consists of properties and methods that are used to find and replace characters that fit in a string.

JavaScript Math Object

Example Match()

<script type="text/javascript">
<!--
var txt = "Los Angels is a magic city";
var a = /angels/i;
document.write(txt.match(a));
//-->
</script>

Result:

Angels

Example Test()

<script type="text/javascript">
<!--
var a=new RegExp("magic");
document.write(a.test("Los Angels is a magic city"));
//-->
</script>

Result:

true

Example Exec()

<script type="text/javascript">
<!--
var a=new RegExp("m");
var b=new RegExp("x");

document.write(a.exec("My Script") + "<br />" + b.exec("My Script"));
//-->
</script>

Result:

m
null