HTML and CSS Reference
forward slashes. After the closing forward slash, options may be provided to modify
the search pattern. The options are i , g , and m . See Table 17.1.
Table 17.1 Options Used for Modifying Search Patterns
Used to ignore case.
Used to match for all occurrences of the pattern in the string.
Used to match over multiple lines.
var variable_name = /regular expression/options;
var myreg = /love/;
var reobj = /san jose/ig;
If you are not going to change the regular expression, say, if it is hard-coded right into
your script, then this literal notation is faster, because the regular expression is evaluated
The constructor method, called RegExp() , creates a RegExp object. The RegExp() con-
structor takes one or two arguments. The first argument is the regular expression; it is a
string representing the regular expression, for example, “green” represents the literal
regular expression /green/ . The second optional argument is called a flag such as i for
case insensitivity or g for global. The constructor method is used when the regular
expression is being provided from some other place, such as from user input, and can
change throughout the run of the program. This method is handled at runtime.
var variable_name = new RegExp("regular expression", "options");
var myreg = new RegExp("love");
var reobj = new RegExp("san jose", "ig");