RegExp pattern - grouping (Definition)

Sometimes you may want to group several items to treat them conditionally or repetitively. The grouping operator provides the means to do that.

Availability:

ECMAScript edition - 3

The parentheses grouping operator works inside regular expressions much as you would expect it to. Everything inside the parentheses can be operated on by a repetition. This example matches the word java or javascript:

/java(script)?/

The grouping operator is also used to delimit sub-strings.

See also:RegExp pattern, RegExp pattern - extension syntax, RegExp pattern - references, RegExp pattern - sub-patterns, RegExp.$n, RegExp.lastParen

Cross-references:

ECMA 262 edition 3 - section - 15.10.1

ECMA 262 edition 3 - section - 15.10.2.8