1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: Parenthesis and Parentheses

By Al Lukaszewski, About.com

Definition:
>>> import re
>>> list = ['cat', 'car', 'cap', 'cab', 'cad', 'can', 'Cancun', 'Katze', 'Auto', 'Deckel', 'Droschke', 'Flegel', 'Dose', 'Vogel', 'CHAT', 'VOITURE', 'CHAPEAU', 'CABINE', 'DAO', 'BIDON', 'BONBON']
>>> y = re.compile('([cCD]a)|([KAB][uI])')
>>> for x in list:
...     if re.search(y,x):
...             print x
...
cat
car
cap
cab
cad
can
Cancun
Auto
CABINE
BIDON

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. Grouping and Alternating
  7. Python RegEx - Python Regular Expressions - Examples - Parenthesis and Parentheses

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

All rights reserved.