Definition:
Back to the main index of this glossary
>>> 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('(?<=wide and)) starry')
>>> z = re.split(y,x)
>>> z
['\nBeneath the wide and', 'wide and', ' 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']
>>> z = re.search(y,x)
>>> print z.group(0)
starry
>>> print z.group(1)
wide and
>>> y = re.compile('(?<=(wide)) and')
>>> z = re.split(y,x)
>>> for i in z: print i
...
Beneath the wide
wide
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, home from sea,
And the hunter home from the hill.
-- "Requiem" by Robert Louis Stevenson
Back to the main index of this glossary
