RegEx Quantifiers Flashcards
Matches any string that contains at least one n
n+
Matches any string that contains zero or more occurrences of n
n*
Matches any string that contains zero or one occurrences of n
n?
Matches any string that contains a sequence of X n’s
n{X}
Matches any string that contains a sequence of X to Y n’s
n{X,Y}
Matches any string that contains a sequence of at least X n’s
n{X,}
Matches any string with n at the end of it
n$
Matches any string with n at the beginning of it
^n
Matches any string that is followed by a specific string n
?=n
Matches any string that is not followed by a specific string n
?!n
RegExp.$1-$9
Description
The $1, …, $9 properties are static, they are not a property of an individual regular expression object. Instead, you always use them as RegExp.$1, …, RegExp.$9.
The values of these properties are read-only and modified whenever successful matches are made.
The number of possible parenthesized substrings is unlimited, but the RegExp object can only hold the first nine. You can access all parenthesized substrings through the returned array’s indexes.
These properties can be used in the replacement text for the String.replace method. When used this way, do not prepend them with RegExp. The example below illustrates this. When parentheses are not included in the regular expression, the script interprets $n’s literally (where n is a positive integer).