This is useful to do remarkably often. Standard Module re The re module obsoletes the regex and regsub modules that you may see used in some older Python code. While there are a few, limited advantages to regex still, they are minor and not worth using in new code. The obsolete modules are likely to be dropped from future Python releases, and 1.6 is also likely to have an interface-compatible improved re module. So stick with re for regular expressions.
Regular expressions are a complicated topic.
A regular expression is a way of describing a pattern that might occur in a text. The trick is encoding this description in the compact syntax of regular expressions. Even though only one or two lines of code may be involved, those lines will effectively incorporate a small program. The first thing to start with is the smallest bits. The simplest character class is a single character, which is just included in the pattern as a literal.