HIROTA YANO
FREE WEB TOOLS
JP
/
EN

Regex: List of Metacharacters

List of meta characters used in regular expressions. Positioning, Special characters, Lazy, Greedy, Lookahead, Lookbehind, etc.

Positional / Special characters

Positional

MetacharacterDescription
^Beginning of line
$End of line
\ABeginning of string
\zEnd of string
\ZEnd of string
(excluding line endings)
\bWord boundaries
\BNon-word boundaries

* The ^ and $ are used as "beginning and end of line" but this is the case in multiline mode (usually this is the default). In single-line mode, it is the beginning or end of the entire string.

Special characters

MetacharacterDescription
\Escape
\tTab
\nNewline (CR)
\rNewline (LF)
\fNew page
\dDigits
\DNon-digits
\sWhitespace
(space, tab, neewline and new page)
\SNon-whitespace
\wWord
(alphanumeric characters plus "_")
\WNon-word

Wildcards and repetition (quantity specifiers)

DefaultLazyGreedyDescription
.Any one character (excluding line feed code)
**?*+1 character/group immediately preceding 0 or more times
++?++1 character/group immediately preceding 1 or more times
????+1 character/group immediately preceding 0 or 1 times
{n}{n}?{n}+1 character/group immediately preceding n times
{n,}{n,}?{n,}+1 character/group immediately preceding n or more times
{n,m}{n,m}?{n,m}+1 character/group immediately preceding n or more times, but not more than m times.

Default

Match the longest part that matches the condition. Preference is given to matching the entire pattern.

Lazy

Match the shortest part that matches the condition.

Greedy

Match the longest part that matches the condition. No preference is given to matching the entire pattern.

e.g. abcXdefX

RegexResult
Default^.*XabcXdefX
Lazy^.*?XabcX
Greedy^.*+XNot match.*
Greedy^.*+abcXdefX
(*) "^.*+" matches all "abcXdefX", so the last `X` does not match.

Positional

MetacharacterDescription
()Blocking
|Or (strings)
[]Or (one character)

e.g. |

RegexDescription
abc|mno|xyzSimple
abc, mno, or xyz
abc.*X|m+o|xy?zInclude metachar in candidates
abcXXX, mXo, xz, etc.
(abc|mno|xyz)XCombine with other strings
abcX, mnoX, or xyzX
(abc|mno|xyz)*Combine with quantity specifiers
abcabc, mnoabcxyz, etc.

e.g. []

RegexDescription
[abc]Simple (a, b, or c)
[^abc]Negation (Other than a, b, c)
[a-z]Range (lowercase)
[A-Z]Range (uppercase)
[0-9]Range (digits)
[a-zA-Z]Or (a to z or A to Z)
[a-z&&[d-f]]And (a to z and d to f)
[a-z&&[^d-f]]Subtraction (a to z excluding d to f)

Lookahead and Lookbehind

MetacharacterDescriptione.g.Description
?=Positive lookaheadfoo(?=bar)Matches "foo" followed by "bar".
?!Negative lookaheadfoo(?!bar)Matches "foo" not followed by "bar".
?<=Positive lookbehind(?<=bar)fooMatches "foo" preceded by "bar".
?<!Negative lookbehind(?<!bar)fooMatches "foo" not preceded by "bar".