Advertisement
rfmonk

re_simple_compiled.py

Dec 30th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import re
  4.  
  5. # Precompile the patterns
  6. regexes = [re.compile(p)
  7.            for p in ['this', 'that']
  8.            ]
  9. text = 'Does this text match the pattern?'
  10.  
  11. print 'Text: %r\n' % text
  12.  
  13. for regex in regexes:
  14.     print 'Seeking "%s" ->' % regex.pattern,
  15.  
  16.     if regex.search(text):
  17.         print 'match!'
  18.     else:
  19.         print 'no match'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement