The regex Module

(Obsolete) The regex module, shown in Example 14-32, is the old (pre-1.5) regular expression machinery. New code should use re where possible.

Note that regex is faster than the re module used in Python 1.5.2, but slower than the new version used in 1.6 and later.

Example 14-32. Using the regex Module

import regex

text = "Mans crisis of identity in the latter half of the 20th century"

p = regex.compile("latter") # literal
print p.match(text)
print, repr(

p = regex.compile("[0-9]+") # number
print, repr(

p = regex.compile("") # two-letter word
print, repr(

p = regex.compile("w+$") # word at the end
print, repr(

32 latter
51 20
13 of
56 century

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols


Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh © 2008-2020.
If you may any questions please contact us: