Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2010 Doug Hellmann. All rights reserved.
  5. #
  6. """Searching a substring of the input.
  7. """
  8. #end_pymotw_header
  9.  
  10. import re
  11.  
  12. text = 'This is some text -- with punctuation.'
  13. pattern = re.compile(r'\b\w*is\w*\b')
  14.  
  15. print 'Text:', text
  16. print
  17.  
  18. pos = 0
  19. while True:
  20. match = pattern.search(text, pos)
  21. if not match:
  22. break
  23. s = match.start()
  24. e = match.end()
  25. print ' %2d : %2d = "%s"' % \
  26. (s, e-1, text[s:e])
  27. # Move forward in text for the next search
  28. pos = e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement