Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # basic_regex_demo.py
- import re
- myRegex = '(?:\.(?:end$|test(?:ed|ing|ify))|^start)'
- def okay(test):
- print test,'=', re.findall(myRegex,test)
- okay('xxxtestxxx') # None
- okay('xxx.testxxx') # None
- okay('xxxtestedxxx') # None
- okay('xxx.testedxxx') # Found
- okay('xxx.testingxxx') # Found
- okay('xxxxxxstart') # None
- okay('startxxxxxx') # Found
- okay('xxxxxx.end') # Found
- okay('xxxxx.endx') # None
- okay('xxxxxxend') # None
- print
- def okay(test):
- print test,'=', bool(re.search(myRegex,test))
- okay('xxx.testedxxx') # True
- okay('xxxtestedxxx') # False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement