<TITLE>regex – Python library reference</TITLE>
Next: <A HREF="../r/regsub" TYPE="Next">regsub</A>
Prev: <A HREF="../s/string" TYPE="Prev">string</A>
Up: <A HREF="../s/string_services" TYPE="Up">String Services</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H1>4.2. Built-in Module <CODE>regex</CODE></H1>
This module provides regular expression matching operations similar to
those found in Emacs. It is always available.
<P>
By default the patterns are Emacs-style regular expressions
(with one exception). There is
a way to change the syntax to match that of several well-known
UNIX utilities. The exception is that Emacs' `<SAMP></SAMP>'
pattern is not supported, since the original implementation references
the Emacs syntax tables.
<P>
This module is 8-bit clean: both patterns and strings may contain null
bytes and characters whose high bit is set.
<P>
<B>Please note:</B> There is a little-known fact about Python string
literals which means that you don't usually have to worry about
doubling backslashes, even though they are used to escape special
characters in string literals as well as in regular expressions. This
is because Python doesn't remove backslashes from string literals if
they are followed by an unrecognized escape character.
<I>However</I>, if you want to include a literal <DFN>backslash</DFN> in a
regular expression represented as a string literal, you have to
<I>quadruple</I> it. E.g. to extract LaTeX `<SAMP>