SETS

A Set is a set of characters enclosed in ‘[]’ brackets. Sets are used to match a single character in the set of characters specified between brackets. Below is the list of Sets:

Set Description
\{n,\} Quantifies the preceding character or group and matches at least n occurrences.
* Quantifies the preceding character or group and matches zero or more occurrences.
[0123] Matches the specified digits (0, 1, 2, or 3)
[^arn] matches for any character EXCEPT a, r, and n
\d Matches any digit (0-9).
[0-5][0-9] matches for any two-digit numbers from 00 and 59
\w Matches any alphanumeric character (a-z, A-Z, 0-9, or _).
[a-n] Matches any lower case alphabet between a and n.
\D Matches any non-digit character.
[arn] matches where one of the specified characters (a, r, or n) are present
[a-zA-Z] matches any character between a and z, lower case OR upper case
[0-9] matches any digit between 0 and 9

Regular Expression (RegEx) in Python with Examples

A Regular Expression or RegEx is a special sequence of characters that uses a search pattern to find a string or set of strings.

It can detect the presence or absence of a text by matching it with a particular pattern and also can split a pattern into one or more sub-patterns.

Similar Reads

Regex Module in Python

Python has a built-in module named “re” that is used for regular expressions in Python. We can import this module by using the import statement....

How to Use RegEx in Python?

...

Metacharacters

You can use RegEx in Python after importing re module....

Special Sequences

...

RegEx Functions

Metacharacters are the characters with special meaning....

1. re.findall()

...

2. re.compile()

...

3. re.split()

...

4. re.sub()

...

5. re.subn()

...

6. re.escape()

Special sequences do not match for the actual character in the string instead it tells the specific location in the search string where the match must occur. It makes it easier to write commonly used patterns....

7. re.search()

re module contains many functions that help us to search a string for a match....

SETS

Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found....

Match Object

...