An object that contains a regular expression pattern along with flags that identify how to apply the pattern.
Syntaxre = / pattern / [ flags ]
re = new RegExp(" pattern " [ ," flags " ] )
The following example illustrates the use of the Regular Expression object by creating an object (re) containing a regular expression pattern with its associated flags. In this case, the resulting Regular Expression object is then used by the match method:
function MatchDemo(){
var s = "through the pages of the book";
var re = new RegExp("the", "i");
var r = s.match(re);
return(r);
}
Remarks
The Regular Expression object should not be confused with the global RegExp object. Even though they sound the same, they are separate and distinct. The properties of the Regular Expression object contain only information about one particular Regular Expression instance, while the properties of the global RegExp object contain continually updated information about each match as it occurs.
Regular Expression objects store patterns used when searching strings for character combinations. After the Regular Expression object is created, it is either passed to a string method, or a string is passed to one of the regular expression methods. Information about the most recent search performed is stored in the global RegExp object.
Use Syntax 1 when you know the search string ahead of time. Use Syntax 2 when the search string is changing frequently, or is unknown, such as strings taken from user input.
The pattern argument is compiled into an internal format before use. For Syntax 1, pattern is compiled as the script is loaded. For Syntax 2, pattern is compiled just before use, or when the compile method is called.
PropertiesThe following table lists the properties of the regular expression object.
FunctionsThe following table lists the functions of the regular expression object.
MethodsThe following table lists the methods of the regular expression object.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4