Advertisement
rfmonk

re_simple_match.py

Dec 30th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import re
  4.  
  5. pattern = 'this'
  6. text = 'Does this text match the pattern?'
  7.  
  8. match = re.search(pattern, text)
  9.  
  10. s = match.start()
  11. e = match.end()
  12.  
  13. print 'Found "%s"\nin "%s"\from %d to %d ("%s")' % \
  14.     (match.re.pattern, match.string, s, e, text[s:e])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement