1. Home
  2. Computing & Technology
  3. Python

Python Regular Expression Examples: Equality

From , former About.com Guide

Definition:
>>> import re
>>> x = '\nBeneath the wide and starry sky, \nDig the grave and let me lie, \nGlad did I live and gladly die, \nAnd I lay me down with a will:\n\nThis be the verse you grave for me: \nHere he lies where he longed to be, \nHome is the sailor, home from sea, \nAnd the hunter home from the hill.\n\n-- "Requiem" by Robert Louis Stevenson\n\n'
>>> y = re.compile('home (?=from)')
>>> z = re.search(y,x)
>>> for i in z:
>>>     print i
...

Beneath the wide and starry sky,
Dig the grave and let me lie,
Glad did I live and gladly die,
And I lay me down with a will:

This be the verse you grave for me:
Here he lies where he longed to be,
Home is the sailor,
from sea,
And the hunter
from the hill.

-- "Requiem" by Robert Louis Stevenson

Back to the main index of this glossary
Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

All rights reserved.