.*
Guia Rápido

Guia Rápido de Regex

Referência completa de sintaxe de expressões regulares para ter sempre à mão no dia a dia.

Classes de Caracteres

SintaxeDescrição
.Any character except newline
\dAny digit (0-9)
\DAny non-digit
\wWord character (letter, digit, underscore)
\WNon-word character
\sAny whitespace (space, tab, newline)
\SAny non-whitespace
[abc]Any one of a, b, or c
[^abc]Any character except a, b, or c
[a-z]Any character in range a to z
[0-9]Any digit (same as \d)

Quantificadores

SintaxeDescrição
*Match 0 or more times (greedy)
+Match 1 or more times (greedy)
?Match 0 or 1 time (optional)
{n}Match exactly n times
{n,}Match n or more times
{n,m}Match between n and m times
*?Match 0 or more times (lazy)
+?Match 1 or more times (lazy)
??Match 0 or 1 time (lazy)

Âncoras e Limites

SintaxeDescrição
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary

Grupos e Retrovisores

SintaxeDescrição
(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named capturing group
\1Backreference to group 1
\k<name>Named backreference
(a|b)Alternation (OR)

Lookahead e Lookbehind

SintaxeDescrição
(?=abc)Positive lookahead — followed by abc
(?!abc)Negative lookahead — NOT followed by abc
(?<=abc)Positive lookbehind — preceded by abc
(?<!abc)Negative lookbehind — NOT preceded by abc

Modificadores (Flags)

SintaxeDescrição
gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line boundaries
sDotall — . matches newlines too
uUnicode mode
vUnicode sets (extended)
dGenerate indices for matches
ySticky — match from lastIndex only

Caracteres Especiais

SintaxeDescrição
\nNewline
\rCarriage return
\tTab
\0Null character
\\Literal backslash
\.Literal dot
\[Literal opening bracket