April 2024
Beginner to intermediate
500 pages
24h 20m
English
The following is a list of some simple regular expression patterns:
| Expression | Meaning |
|---|---|
| . | Matches any single character. |
| [abc] | Matches a, b, or c. |
| [^abc] | Matches any characters other than a, b, or c. |
| [abc]+ | Matches one or more occurrences of the characters abc—for example, match b or aba or ccba. |
| [abc]+[de]* | Matches zero or more occurrences of the characters abcde—for example, match b or aba or bd or abae. |
| (regex) | Creates a capture group. |
| $ | Ends with. |
Table B.22 summarizes the main regular expression functions in the re module. To use these functions, first import re.
Table B.22 Regular Expression Module Functions and Methods
| Method Name | Use | Explanation |
|---|---|---|
| match(pattern, string) | re.match('[abc]XY.', ... |
Read now
Unlock full access