1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: Calling Regular Expressions

By Al Lukaszewski, About.com

Definition:
>>> import re
>>> u = 'Four score and seven years ago, our forefathers...'
>>> y = re.compile('a(?:[rg]).*(?P<another>for(?:e))')
>>> z = re.search(y,u)
>>> print z.group()
ars ago, our fore
>>> print z.group(0)
ars ago, our fore
>>> print z.group(1)
fore
>>> print z.groups()
('fore',)
>>> print z.group('another')
fore

Back to the main index of this glossary

Explore Python

More from About.com

  1. Home
  2. Computing & Technology
  3. Python
  4. Regular Expressions
  5. Python RegEx Examples
  6. Parenthetical Compounds
  7. Python RegEx - Python Regular Expressions - Examples - Calling Regular Expressions by Name

©2008 About.com, a part of The New York Times Company.

All rights reserved.