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.