Guest User

Untitled

a guest
Mar 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Foo():
  2. _rex = re.compile("d+")
  3. def bar(self, string):
  4. m = _rex.match(string)
  5. if m != None:
  6. doStuff()
  7.  
  8. >>> s="1234n"
  9. >>> re.search("^d+Z",s)
  10. >>> s="1234"
  11. >>> re.search("^d+Z",s)
  12. <_sre.SRE_Match object at 0xb762ed40>
  13.  
  14. re.match(r'd+$') # re.match anchors the match at the start of the string, so $ is what remains to add
  15.  
  16. re.match(r'd+Z') # Z will only match at the very end of the string
  17.  
  18. re.search(r'^d+$')
  19. re.search(r'Ad+Z')
  20.  
  21. _rex = re.compile("d+")
  22. if _rex.fullmatch(s):
  23. doStuff()
Add Comment
Please, Sign In to add comment