contents   index   previous   next



Regular expression attributes

The following table lists allowable attribute characters and their effects on a regular expression. No other characters are allowed as attributes.

 

Character

Attribute meaning

 

g

Do a global match. Allow the finding of all matches in a string using the RegExp and String methods and properties that allow global operations. The instance property global is set to true.

 

Example: /pattern/g

 

i

Do case insensitive matches. The instance property ignoreCase is set to true.

 

Example: /pattern/i

 

m

Work with multiple lines in a string. When working with multiple lines the "^" and "$" anchor characters will match the start and end of a string and the start and end of lines within the string. The newline character "\n" in a string indicates the end of a line and hence lines in a string. The instance property multiline is set to true.

 

Example: /pattern/m

 

 

Attributes are the characters allowed after the end slash "/" in a regular expression pattern. The following regular expressions illustrate the use of attributes.

 

var pat = /^The/i;    // any form of "the" at start of a string

var pat = /the/g;     // all occurrences of "the" may be found

var pat = /test$/m;   // first "test" at the end of any line

var pat = /test$/igm; // all forms of "test" at end of all lines

   // The following four examples do the same as the first four

var pat = new RegExp("^The",  "i");

var pat = new RegExp("the",   "g");

var pat = new RegExp("test$", "m");

var pat = new RegExp("test$", "igm");

 


Regular expression special characters