Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo():
- _rex = re.compile("d+")
- def bar(self, string):
- m = _rex.match(string)
- if m != None:
- doStuff()
- >>> s="1234n"
- >>> re.search("^d+Z",s)
- >>> s="1234"
- >>> re.search("^d+Z",s)
- <_sre.SRE_Match object at 0xb762ed40>
- re.match(r'd+$') # re.match anchors the match at the start of the string, so $ is what remains to add
- re.match(r'd+Z') # Z will only match at the very end of the string
- re.search(r'^d+$')
- re.search(r'Ad+Z')
- _rex = re.compile("d+")
- if _rex.fullmatch(s):
- doStuff()
Add Comment
Please, Sign In to add comment