What are character classes or character sets used in Python regular ...
In this chapter, we will understand character classes , how they work, and provide simple examples and programs to explain their usage. One of the main components of regular expressions is character classes or character sets.
Download our Python regular expressions cheat sheet for syntax, character classes , groups, and re module functions—ideal for pattern matching.
re Regular expression operations Python 3.14.6 documentation

So r"\n" is a two- character string containing '\' and 'n', while "\n" is a one- character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation. It is important to note that most regular expression operations are available as module-level functions and methods on compiled regular expressions .
Regular Expressions (Regex) are patterns used in Python for searching, matching, validating, and replacing text. This cheat sheet offers a quick reference to common regex patterns and symbols. Basic Characters

Python RegEx
Regular Expression (RegEx) is a powerful tool used to search, match, validate, extract or modify text based on specific patterns. In Python , the built- in re module provides support for using RegEx. It allows you to define patterns using special characters like \d for digits, ^ for the beginning of a string and many more.
A RegEx, or Regular Expression , is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern.

Character Classes and Shorthands
This lesson introduces character classes in regular expressions , showing how to define custom sets of characters , use ranges, and apply shorthand notations like \\d, \\w, and \\s. It explains how to combine these with quantifiers to match patterns such as hexadecimal values and words, and demonstrates the use of negated character classes for extracting content between delimiters.
The regex special sequence represents the basic predefined character classes and character classes are sets of characters enclosed by square brackets [].

Regular expression HOWTO Python 3.14.6 documentation
Regular expression HOWTO ¶ Author: A.M. Kuchling <amk @ amk. ca> Abstract This document is an introductory tutorial to using regular expressions in Python with the re module. It provides a gentler introduction than the corresponding section in the Library Reference. Introduction ¶ Regular expressions (called REs, or regexes, or regex patterns) are essentially a tiny, highly specialized ...








Range of characters Character classes have their own metacharacters to help define the sets succinctly. Metacharacters outside of character classes like ^, $, () etc either don't have special meaning or have a completely different one inside the character classes . First up, the - metacharacter that helps to define a range of characters instead of having to specify them all individually.