Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import re
- text = 'This is some text -- with punctuation.'
- print text
- print
- for pattern in [r'^(?P<first_word>\w+)',
- r'(?P<last_word>\w+)\S*$',
- r'(?P<t_word>\bt\w+)\W(?P<other_word>\w+)',
- r'(?P<ends_with_t>\w+t)\b',
- ]:
- regex = re.compile(pattern)
- match = regex.search(text)
- print 'Matching "%s"' % pattern
- print ' ', match.groups()
- print ' ', match.groupdict()
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement