The regular expression objects have the following properties.
Properties | Description |
---|---|
global | If this property is false, which is the default, the search stops when the first match is found. Set this to true if you want all matches. |
ignoreCase | Case sensitive match or not, defaults to false. |
multiline | Search matches that may span over more than one line, defaults to false. |
lastIndex | The position at which to start the search, defaults to 0. |
source | Contains the regexp pattern. |
None of these properties, except for lastIndex, can be changed once the object has created.
The first three parameters represent the regex modifiers. If you create a regex object using the constructor, you can pass any combination of the following characters as a second parameter:
"g"
for global"i"
for ignoreCase"m"
for multilineThese letters can be in any order. If a letter is passed, the corresponding modifier is set to true. In the following example, all modifiers are set to true:
var re = new RegExp('j.*t', 'gmi');
Let's verify:
re.global; true
Once set, the modifier cannot be changed:
re.global = false; re.global true
To set any modifiers using the regex literal, you add them after the closing slash.
var re = /j.*t/ig; re.global