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('ho'(?is)
File "<stdin>", line 1
y = re.compile('ho'(?is)
^
SyntaxError: invalid syntax
>>> y = re.compile('ho(?is)')
>>> z = re.split(y,x)
>>> z
['\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, \n', 'me is the sailor, ', 'me from sea, \nAnd the hunter ', 'me from the hill.\n\n-- "Requiem" by Robert Louis Stevenson\n\n']
>>> y = re.compile('^ho(?ismx)')
>>> z = re.split(y,x)
>>> z
['\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, \n', 'me 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('(die,...nd)(?msx)')
>>> z = re.split(y, x)
>>> z
['\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']
Back to the main index of this glossary
