15.2. Special Symbols and Characters for REs
We will now introduce the most popular of the metacharacters, special characters and symbols, which give regular expressions their power and flexibility. You will find the most common of these symbols and characters in Table 15.1.
Notation | Description | Example RE |
---|---|---|
Symbols | ||
re_string | match literal string value re_string | foo |
re1|re2 | match literal string value re1 or re2 | foo|bar |
. | match any character (except NEWLINE) | ::.+:: |
^ | match start of string | ^Dear |
$ | match end of string | /bin/\w*sh$ |
* | match 0 or more occurrences of preceding RE | [A-Za-z]\w* |
+ | match 1 or more occurrences of preceding RE | \d+\.|\.\d+ |
? | match 0 or 1 occurrence(s) of preceding RE | goo? |
{N} | match N occurrences ... |
Get Core Python Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.