O'Reilly logo

XML Processing with Python by Sean McGrath

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.7. Introducing Regular Expressions

The Python standard library provides a module known as re for regular expression processing. For full information on re, see the documentation at Doc\lib\module-re.html. Also, a “how to guide” to regular expressions can be found at http://www.python.org/doc/howto/.

The simplest way to use the re module is to use the search function. It takes two parameters—the pattern and the string to be searched. If the search succeeds, the function returns an object known as a match object. If it fails, it returns None. Every match object provides methods called start() and end() that can be used to retrieve the start and end offsets of the matching string, respectively.

CD-ROM reference=7047.txt
>>> import re
>>> # Search ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required