Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # encoding: utf-8
- #
- # Copyright (c) 2010 Doug Hellmann. All rights reserved.
- #
- """Searching a substring of the input.
- """
- #end_pymotw_header
- import re
- text = 'This is some text -- with punctuation.'
- pattern = re.compile(r'\b\w*is\w*\b')
- print 'Text:', text
- print
- pos = 0
- while True:
- match = pattern.search(text, pos)
- if not match:
- break
- s = match.start()
- e = match.end()
- print ' %2d : %2d = "%s"' % \
- (s, e-1, text[s:e])
- # Move forward in text for the next search
- pos = e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement