Advertisement
here2share

# basic_regex_demo.py

Jul 24th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # basic_regex_demo.py
  2.  
  3. import re
  4. myRegex = '(?:\.(?:end$|test(?:ed|ing|ify))|^start)'
  5.  
  6. def okay(test):
  7.         print test,'=', re.findall(myRegex,test)
  8. okay('xxxtestxxx') # None
  9. okay('xxx.testxxx') # None
  10. okay('xxxtestedxxx') # None
  11. okay('xxx.testedxxx') # Found
  12. okay('xxx.testingxxx') # Found
  13. okay('xxxxxxstart') # None
  14. okay('startxxxxxx') # Found
  15. okay('xxxxxx.end') # Found
  16. okay('xxxxx.endx') # None
  17. okay('xxxxxxend') # None
  18. print
  19. def okay(test):
  20.     print test,'=', bool(re.search(myRegex,test))
  21. okay('xxx.testedxxx') # True
  22. okay('xxxtestedxxx') # False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement