加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: the Carat

By Al Lukaszewski, About.com

Definition:
>>> import re
>>> list = ['cat', 'car', 'cap', 'cab', 'cad', 'can', 'Katze', 'Auto',
'Deckel', 'Droschke', 'Flegel', 'Dose', 'CHAT', 'VOITURE', 'CHAPEAU',
'CABINE', 'DAO', 'BIDON']
>>> y = re.compile('^Dose')
>>> for x in list:
...     if y.match(x):
...             print x
...
Dose
>>> y = re.compile('^cad')
>>> for x in list:
...     if y.match(x):
...             print x
...
cad
>>> y = re.compile('^c.*')
>>> function(y)
cat
car
cap
cab
cad
can

Back to the main index of this glossary

Explore Python

More from About.com

New Year, New You

Take action today to accomplish your biggest goals with these motivating ideas.

Best Moves in a Bad Economy

Stay on top in this tough economy with our smart, easy-to-follow financial tips.

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Regular Expressions
  5. Python RegEx Examples
  6. String Locations
  7. Python RegEx - Python Regular Expressions - Examples - the Carat

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

All rights reserved.