Regex Cheat Sheet

ADVERTISEMENT

REGEX CHEAT SHEET
The most commonly used metacharacters in Python, PHP, Perl, and JavaScript regular expressions
Metacharacters
Meaning
\n
Newline
[…]
Range
[^…]
Not in range
.
Any character except newline
\w
Word character [a-zA-Z0-9_]
\W
Nonword character [^a-zA-Z0-9_]
\d
Digit character [0-9]
\D
Nondigit character [^0-9]
\s
Whitespace character [\n\r\f\t]
\S
Nonwhitespace character [^\n\r\f\t]
^
Start of string
$
End of string
\b
Word boundary
\B
Not-word-boundary
i
Case-insensitive matching
m
^ and $ match next to embedded \n
(…)
Group subpattern and capture submatch into \1, \2, ..
Contains the result of nth earlier submatch from a parentheses capture group, or a named capture
\n
group
*
Match 0 or more times
+
Match 1 or more times
?
Match 1 or 0 times
{n}
Match exactly n times
Don’t forget to visit

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go