1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: Compound RegEx: '*?'

By Al Lukaszewski, About.com

Definition: *?
>>> import re
>>> y = re.split('(<.*>)', '<a href="http://www.some-url.com">some hyperlink</a>')
>>> print y
['', '<a href="http://www.some-url.com">some hyperlink</a>', '']
>>>
>>> y = re.split('(<.*?>)', '<a href="http://www.some-url.com">some hyperlink</a>')
>>> print y
['', '<a href="http://www.some-url.com">', 'some hyperlink', '</a>', '']
>>>
>>> y = re.split('(.,\s.*)', 'Home is the sailor, home from sea, and the hunter home from the hill.')
>>> print y
['Home is the sailo', 'r, home from sea, and the hunter home from the hill.', '']
>>> y = re.split('(.,\s.*?)', 'Home is the sailor, home from sea, and the hunter home from the hill.')
>>> print y
['Home is the sailo', 'r, ', 'home from se', 'a, ', 'and the hunter home from the hill.']

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. Compound Regex
  7. Python RegEx - Python Regular Expressions - Examples - Compound RegEx: '*?'

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

All rights reserved.