Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pattern Syntax Reference

Complete reference for all pattern syntax.

Special Characters

CharacterDescription
.Any character except newline
^Start of string
$End of string
``
\Escape
(, )Groups
[, ]Character class
{, }Quantifier or fuzziness

Character Classes

SyntaxDescription
[abc]a, b, or c
[^abc]Not a, b, or c
[a-z]a to z
[A-Za-z]ASCII letters
[0-9]Digits
\dDigit
\DNon-digit
\wWord character
\WNon-word
\sWhitespace
\SNon-whitespace

Quantifiers

SyntaxDescription
*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,}n or more
{n,m}n to m
*?Lazy *
+?Lazy +
??Lazy ?

Fuzziness Markers

SyntaxDescription
{e<=N}Max N edits
{i<=N}Max N insertions
{d<=N}Max N deletions
{s<=N}Max N substitutions
{t<=N}Max N transpositions
{c<=N}Max total cost N
{Ni+Md...<=N}Weighted costs
{e<=N:[class]}Restricted edits
~NShorthand for {e<=N}

Groups

SyntaxDescription
(...)Capture group
(?:...)Non-capture
(?<name>...)Named capture
(?=...)Lookahead
(?!...)Negative lookahead
(?<=...)Lookbehind
(?<!...)Negative lookbehind
(?>...)Atomic group

Flags

SyntaxDescription
(?i)Case insensitive
(?m)Multi-line
(?s)Dot-all
(?x)Verbose
(?U)Ungreedy
(?b)Best match
(?e)Enhance match
(?p)POSIX mode