Python

  1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: the Asterisk

From Al Lukaszewski, for 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('^c.*')
>>> for x in list:
...     if y.match(x):
...             print x
...
cat
car
cap
cab
cad
can
>>> y = re.compile('C.*U')
>>> for x in list:
...     if y.match(x):
...             print x
...
CHAPEAU
>>>

Back to the main index of this glossary

Explore Python

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Regular Expressions
  5. Python RegEx Examples
  6. Character Markers
  7. Python RegEx - Python Regular Expressions - Examples - the Asterisk

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

All rights reserved.