RegExp pattern - attributes (Definition)

The attributes of a regular expression.

Availability:

ECMAScript edition - 3

When you specify a regular expression, it will by default only match the first occurrence that it encounters. It is possible to specify a pattern to match that can occur several times in a line. To match all of these, you can use the 'g' attribute. The 'g' stands for global matching.

There is one other attribute that allows the matching to be carried out in a case-insensitive manner. That is the 'i' attribute.

Both of these attributes are placed after the closing slash at the end of the pattern.

The case-insensitive match works like this:

/javascript/i

would match the following strings

JavaScript

javascript

JAVASCRIPT

JaVaScRiPt

The g attribute applied like this, would cause the pattern:

/0/g

to match every zero in the string:

'0100, 00123, "00067", 666000'

There is another attribute to control whether the pattern is applied to single lines or multiple lines. Because the regular expression is realized as an object, this is controlled by means of an object property accessed via the multi-line identifier, the letter 'm' in JavaScript 1.5 (shipped with Netscape 6.0)

Here is a list of the available attributes:

seqPatternDescriptionJS
00gGlobal match for every occurrence of the pattern throughout the line.1.2
01iCase-insensitive matching.1.2
02igCase-insensitive global match.1.2
13mMultiple lines to be processed. Available only in JavaScript 1.5 and mutually exclusive with the 's' attribute.1.5
15gmGlobal match on multiple lines.1.5
15imCase-insensitive matching on multiple lines.1.5
16igmCase-insensitive global match on multiple lines.1.5

See also:RegExp pattern, RegExp pattern - position, RegExp(), RegExp.multiline

Cross-references:

ECMA 262 edition 3 - section - 15.10.1

ECMA 262 edition 3 - section - 15.10.2.1