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.

Table 15.1. Common Regular Expression Symbols and Special Characters
NotationDescriptionExample RE
Symbols
re_stringmatch literal string value re_stringfoo
re1|re2match literal string value re1 or re2foo|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 REgoo?
{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.