Properties of the RegExp Objects

The regular expression objects have the following properties.

globalIf 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.
ignoreCaseCase sensitive match or not, defaults to false.
multilineSearch matches that may span over more than one line, defaults to false.
lastIndexThe position at which to start the search, defaults to 0.
sourceContains 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 multiline

These 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:;


Once set, the modifier cannot be changed: = false;


To set any modifiers using the regex literal, you add them after the closing slash.

var re = /j.*t/ig;
Related Tutorial
Follow Us #
Contents +