Skip to main content

Regex

import re
text = "..."
pattern = re.compile(r'abc')

matches = pattern.finditer(text)

for match in matches:
print(match)

Regular Expressions Reference

Symbols

SymbolDescription
.Everything but a new line
\dDigits 0 - 9
\DNot a digit
\w(a-z, A-Z, 0-9, _)
\WNot a "normal" character
\sWhitespace (space, tab, new line)
\SNot a Whitespace
\bWord Boundary (space before)
^Start of string
$End of string

More Symbols

SymbolDescription
[ ]Matches character
[^ ]Not in brackets
``
{3,4}Range
[a-g]Character between a & g
{3}Exact
*0 or more
+1 or more
?0 or 1

Escaping Special Characters

\. \* \\ - Escaped special characters


Flags

SymbolDescriptionExample
/iCase-insensitive/aBc/i would match AbC.
/mMultiline. ^ and $ match start and end of lines./^[\s\S]+$/m
[]Matches character