Advertisement
rfmonk

re_groups_individual.py

Jan 2nd, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import re
  5.  
  6. text = 'This is some text -- with punctuation.'
  7.  
  8. print 'Input text           :', text
  9.  
  10. # word starting with 't' then another word
  11. regex = re.compile(r' (\bt\w+)\W+(w+)')
  12. print 'Pattern              :', regex.pattern
  13.  
  14. match = regex.search(text)
  15. print 'Entire match         :',  match.group(0)
  16. print 'Word starting with "t":', match.group(1)
  17. print 'Word after "t" word  :',  match.group(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement