Zum Inhalt springen
uencoder

Regex Syntax Spickzettel

Quick Referenz für regular expression metacharacters, anchors, groups, und escapes.

Anchors and Boundaries

Anchors assert a position in the string without consuming characters. The caret matches the start of the string or line, and the dollar sign matches the end. Word boundary assertions match the transition between a word and non-word character. Anchors are zero-width, so they do not advance the match position. Multiline flags change whether caret and dollar match line boundaries or just string boundaries.

^
Start of string or line
^Hello
$
End of string or line
world$
\b
Word boundary
\bword\b
\B
Non-word boundary
\Bword
\A \z
Absolute start and end (no multiline)
\Astart

Groups and Backreferences

Parentheses create capturing groups that store the matched substring for later use via backreferences. Non-capturing groups use the question-mark-colon prefix and do not store the match. Named groups use the question-mark-angle syntax and can be referenced by name. Backreferences allow matching repeated text such as quoted strings or HTML tags. Excessive backreferences can cause catastrophic backtracking on certain patterns.

Lookarounds

Lookahead and lookbehind assertions match a position based on what follows or precedes without consuming text. Positive lookaheads use question-mark-equals and negative use question-mark-bang. Lookbehinds were historically fixed-width but modern engines support variable-width. Lookarounds are useful for validating context without including it in the match, such as matching a digit only when preceded by a letter.

Verwandte Tools

参考链接