DRIVER=processor
MODALIAS=cpu:type:x86,ven0000fam0006mod0055:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0017,0018,0019,001A,002B,0034,003A,003B,003D,0068,006F,0070,0072,0074,0075,0079,007F,0080,0081,0089,008C,008D,0091,0093,0094,0095,0096,0097,0098,0099,009A,009B,009C,009D,009E,009F,00C0,00C5,00C8,00E7,00EB,00EC,00ED,00F0,00F1,00F3,00F5,00F9,00FA,00FD,00FF,0114,0115,0120,0123,0124,0125,0127,0128,0129,012A,012B,012E,0130,0131,0132,0133,0134,0138,013C,013E,013F,0140,0141,0142,0165,024A,025A,025F,0282,02A1,02A4

  $    ‹      sËÌIUÈË/QHË/ÍKÑã +�©!     ,   ˆl–Ü4ý() v( õõÀ»q¡)‹FÿÅ„pAeÏ_‡I|¥ŠèªÅÄ ?÷     .. _regex-howto:

****************************
  Regular Expression HOWTO
****************************

:Author: A.M. Kuchling <amk@amk.ca>

.. TODO:
   Document lookbehind assertions
   Better way of displaying a RE, a string, and what it matches
   Mention optional argument to match.groups()
   Unicode (at least a reference)


.. topic:: Abstract

   This document is an introductory tutorial to using regular expressions in Python
   with the :mod:`re` module.  It provides a gentler introduction than the
   corresponding section in the Library Reference.


Introduction
============

The :mod:`re` module was added in Python 1.5, and provides Perl-style regular
expression patterns.  Earlier versions of Python came with the :mod:`regex`
module, which provided Emacs-style patterns.  The :mod:`regex` module was
removed completely in Python 2.5.

Regular expressions (called REs, or regexes, or regex patterns) are essentially
a tiny, highly specialized programming language embedded inside Python and made
available through the :mod:`re` module. Using this little language, you specify
the rules for the set of possible strings that you want to match; this set might
contain English sentences, or e-mail addresses, or TeX commands, or anything you
like.  You can then ask questions such as "Does this string match the pattern?",
or "Is there a match for the pattern anywhere in this string?".  You can also
use REs to modify a string or to split it apart in various ways.

Regular expression patterns are compiled into a series of bytecodes which are
then executed by a matching engine written in C.  For advanced use, it may be
necessary to pay careful attention to how the engine will execute a given RE,
and write the RE in a certain way in order to produce bytecode that runs faster.
Optimization isn't covered in this document, because it requires that you have a
good understanding of the matching engine's internals.

The regular expression language is relatively small and restricted, so not all
possible string processing tasks can be done using regular expressions.  There
are also tasks that *can* be done with regular expressions, but the expressions
turn out to be very complicated.  In these cases, you may be better off writing
Python code to do the processing; while Python code will be slower than an
elaborate regular expression, it will also probably be more understandable.


Simple Patterns
===============

We'll start by learning about the simplest possible regular expressions.  Since
regular expressions are used to operate on strings, we'll begin with the most
common task: matching characters.

For a detailed explanation of the computer science underlying regular
expressions (deterministic and non-deterministic finite automata), you can refer
to almost any textbook on writing compilers.


Matching Characters
-------------------

Most letters and characters will simply match themselves.  For example, the
regular expression ``test`` will match the string ``test`` exactly.  (You can
enable a case-insensitive mode that would let this RE match ``Test`` or ``TEST``
as well; more about this later.)

There are exceptions to this rule; some characters are special
:dfn:`metacharacters`, and don't match themselves.  Instead, they signal that
some out-of-the-ordinary thing should be matched, or they affect other portions
of the RE by repeating them or changing their meaning.  Muc