Regex: List of Tokes

DescriptionExtended descriptionExample

A single character of: a, b or c

Matches either an a, b or c character

[abc]

A character except for: a, b or c

Matches any character except for an a, b or c

[^abc]

A character in the range: a-z

Matches any characters between a and z, including a and z.

[a-z]

A character not in the range: a-z

Matches any characters except those in the range a-z.

[^a-z]

A character in the range: a-z or A-Z

Matches any characters between a-z or A-Z. You can combine as much as you, please.

[a-zA-Z]

Any single character

Matches any character other than newline (or including line terminators with the /s flag)

.

Alternate - match either a or b

Matches either what is before the | or what is after it - in this case `a` or `b`.

a|b

Any whitespace character

Matches any space, tab or newline character.

\s

Any non-whitespace character

Matches anything other than a space, tab or newline.

\S

Any digit

Matches any decimal digit. Equivalent to [0-9].

\d

Any non-digit

Matches anything other than a decimal/digit.

\D

Any word character

Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_].

\w

Any non-word character

Matches anything other than a letter, digit or underscore. Equivalent to [^a-zA-Z0-9_]

\W

Match everything enclosed

A non-capturing group allows you to apply quantifiers to part of your regex but does not capture/assign an ID.

(?:...)

Capture everything enclosed

Isolates part of the full match to be later referred to by ID within the regex or the matches array. IDs start at 1.

(...)

Zero or one of a

Matches an `a` character or nothing.

a?

Zero or more of a

Matches zero or more consecutive `a` characters.

a*

One or more of a

Matches one or more consecutive `a` characters.

a+

Exactly 3 of a

Matches exactly 3 consecutive `a` characters.

a{3}

3 or more of a

Matches at least 3 consecutive `a` characters.

a{3,}

Between 3 and 6 of a

Matches between 3 and 6 (inclusive) consecutive `a` characters.

a{3,6}

Start of string

Matches the start of a string without consuming any characters. If /m multiline mode is used, this will also match immediately after a newline character.

^

End of string

Matches the end of a string without consuming any characters. If multiline mode is used, this will also match immediately before a newline character.

$

A word boundary

Matches, without consuming any characters, immediately between a character matched by \w and a character not matched by \w (in either order). It cannot be used to separate non words from words.

\b

Non-word boundary

Matches, without consuming any characters, at the position between two characters matched by \w.

\B

Newline

Matches a newline character

\n

Carriage return

Matches a carriage return, unicode character U+2185.

\r

Tab

Matches a tab character. Historically, tab stops happen every 8 characters.

\t

Null character

Matches a null character, most often visually represented in Unicode using U+2400.

\0

Positive Lookahead

Asserts that the given subpattern can be matched here, without consuming characters

(?=...)

Negative Lookahead

Starting at the current position in the expression, ensures that the given pattern will not match. Does not consume characters.

(?!...)

Positive Lookbehind

Ensures that the given pattern will match, ending at the current position in the expression. The pattern must have a fixed width. Does not consume any characters.

(?<=...)

Negative Lookbehind

Ensures that the given pattern would not match and end at the current position in the expression. The pattern must have a fixed width. Does not consume characters.

(?<!...)

Last updated

Was this helpful?