GNU Info

Info Node: (python2.1-lib.info)re

(python2.1-lib.info)re


Next: struct Prev: string Up: String Services
Enter node , (file) or (file)node

Regular expression operations
=============================

This module was written by Andrew M. Kuchling <amk1@bigfoot.com>.
This module was written by Fredrik Lundh <effbot@telia.com>.
This manual section was written by Andrew M. Kuchling
<amk1@bigfoot.com>.
Regular expression search and match operations with a Perl-style
expression syntax.

This module provides regular expression matching operations similar to
those found in Perl.  Regular expression pattern strings may not
contain null bytes, but can specify the null byte using the `\NUMBER'
notation.  Both patterns and strings to be searched can be Unicode
strings as well as 8-bit strings.  The `re' module is always available.

Regular expressions use the backslash character (`\') to indicate
special forms or to allow special characters to be used without
invoking their special meaning.  This collides with Python's usage of
the same character for the same purpose in string literals; for
example, to match a literal backslash, one might have to write `'\\\\''
as the pattern string, because the regular expression must be `\\', and
each backslash must be expressed as `\\' inside a regular Python string
literal.

The solution is to use Python's raw string notation for regular
expression patterns; backslashes are not handled in any special way in
a string literal prefixed with `r'.  So `r"\n"' is a two-character
string containing `\' and `n', while `"\n"' is a one-character string
containing a newline.  Usually patterns will be expressed in Python
code using this raw string notation.

*Implementation note:* The `re'  module has two distinct
implementations: `sre' is the default implementation and includes
Unicode support, but may run into stack limitations for some patterns.
Though this will be fixed for a future release of Python, the older
implementation (without Unicode support) is still available as the `pre'
module.

See also:
     `Mastering Regular Expressions'{Book on regular expressions by
     Jeffrey Friedl, published by O'Reilly.  The Python material in
     this book dates from before the `re' module, but it covers writing
     good regular expression patterns in great detail.}

Regular Expression Syntax
Matching vs. Searching
Contents of Module re
Regular Expression Objects
Match Objects

automatically generated by info2www version 1.2.2.9