Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abhinavkorpal/69405e166ea1e4e31d30d9fdf259db3c to your computer and use it in GitHub Desktop.
Save abhinavkorpal/69405e166ea1e4e31d30d9fdf259db3c to your computer and use it in GitHub Desktop.
Python Regular Expressions
\ Used to drop the special meaning of character
following it (discussed below)
[] Represent a character class
^ Matches the beginning
$ Matches the end
. Matches any character except newline
? Matches zero or one occurrence.
| Means OR (Matches with any of the characters
separated by it.
* Any number of occurrences (including 0 occurrences)
+ One ore more occurrences
{} Indicate number of occurrences of a preceding RE
to match.
() Enclose a group of REs
\d Matches any decimal digit, this is equivalent
to the set class [0-9].
\D Matches any non-digit character.
\s Matches any whitespace character.
\S Matches any non-whitespace character
\w Matches any alphanumeric character, this is
equivalent to the class [a-zA-Z0-9_].
\W Matches any non-alphanumeric character.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment