Advertisement
rfmonk

re_flags_multiline.py

Jan 2nd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import re
  5.  
  6. text = 'This is some text -- with punctuation.\nA second line.'
  7. pattern = r'(^\w+) | (\w+\S*$)'
  8. single_line = re.compile(pattern)
  9. multiline = re.compile(pattern, re.MULTILINE)
  10.  
  11. print 'Text:\n %r' % text
  12. print 'Pattern:\n %s' % pattern
  13. print 'Single Line :'
  14. for match in single_line.findall(text):
  15.     print ' %r' % (match,)
  16. print 'Multiline    :'
  17. for match in multiline.findall(text):
  18.     print ' %r' % (match,)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement