source

The source property is a property of the RegExp object, and is used to represent the text being used for the pattern matching. That is, the text the regular expression is looking for. Thw switches used to further refine the regular expression search are not included as values of this property.

syntax:

RegExp.source

EXAMPLE

var searchString = new RegExp("This" | "is");

stringToSearch = new String("This is the searchable text of the regular expression.");

searchArray = searchString.exec(stringToSearch);

document.write("The source of the regular expression is : " + searchString.source);

The example first starts out with the creation of a new RegExp object, called searchString. A new variable is then declared, called stringToSearch. The RegExp object uses this string to search for the two search strings,"This" and "is", which are the parameters of the RegExp object. The exec() method is then used to call the stringToSearch variable containing the text. The documnet.write statement then calls the searchString RegExp object, with the source property to return the text matches.