A term is a matchable unit in a regular expression: a literal character, a character class, or a group. Terms placed in sequence must match in that order; operators such as {5} can qualify a term. section 12.2.2 section 12.7
Literals and character classes
In /test/, each character is a term, so the pattern matches t followed by e, s, and t. In /[az]{5}/, [az] is one term that matches either a or z; {5} requires five repetitions. section 12.2.2 section 12.2.2
Metacharacters have special meaning. Escape one with a backslash to match it literally; for example, /\\/ matches a backslash. Regex literals avoid the extra escaping required when writing the same pattern as a JavaScript string for RegExp. section 12.2.2
Table 12.1 Predefined character classes and character terms
|
Predefined term
|
Matches
|
|
.
|
Any character, except for line break characters unless the
s flag is set
|
|
\d
|
Any decimal digit; equivalent to
[0-9]
|
|
\D
|
Any character but a decimal digit; equivalent to
[^0-9]
|
|
\w
|
Any alphanumeric character including underscore; equivalent to
[A-Za-z0-9_]
|
|
\W
|
Any character but alphanumeric and underscore characters; equivalent to
[^A-Za-z0-9_]
|
|
\s
|
Any whitespace character (space, tab, form feed, and so on)
|
|
\S
|
Any character but a whitespace character
|
|
\b
|
A word boundary
|
|
\B
|
Not a word boundary (inside a word)
|
Use the table to compare predefined character terms, including digit, word, whitespace, and boundary forms. section 12.2.2
