Guest User

Untitled

a guest
Sep 7th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Regex for capture two types of patterns [closed]
  2. XXXX-yyyyy+123131331@gmail.com
  3. XXXX+313131313@gmail
  4.  
  5. /^w+(-w+)?+d+@S+$/
  6.  
  7. ^ # the start of the string
  8. w+ # one or more ascii alhpa-nums
  9. ( # start group 1
  10. - # the literal '-'
  11. w+ # one or more ascii alhpa-nums
  12. )? # end group 1, and make it optional
  13. + # the literal '+'
  14. d+ # one or more digits
  15. @ # the literal '@'
  16. S+ # one or more non-space chars
  17. $ # the end of the string
  18.  
  19. ^(w+)(?:-w+)?+d+@S+$
  20.  
  21. /p{Lu}+(-p{Ll}+)?+d+@gmail.com/
  22.  
  23. /([A-Z0-9._%-]+?)(?:-([A-Z0-9._%]+))?+(d+)@gmail.com/i
  24.  
  25. p = re.compile(r"([A-Z0-9._%+-]+?)(?:-([A-Z0-9._%+]+))?+(d+)@gmail.com", re.IGNORECASE)
  26. m = p.search("XXXX-yyyy+123131313@gmail.com")
  27. m.groups()
  28. # ('XXXX', 'yyyy', '123131313')
  29.  
  30. ( # start capture group 1
  31. [A-Z0-9._%+-] # match the characters in the []
  32. +? # one or more times, lazy
  33. ) # end capture group 1
  34. (?: # start non-capturing group
  35. - # match the literal character '-'
  36. ( # start capture group 2
  37. [A-Z0-9._%+] # match the characters in the []
  38. + # one or more times
  39. ) # end capture group 2
  40. )? # end non-capturing group, matching 1 or 0 times
  41. + # match the literal character '+'
  42. ( # start capture group 3
  43. d+ # match digits [0-9] one or more times
  44. ) # end capture group 3
  45. @gmail.com # match the literal characters '@gmail.com'
  46.  
  47. X.X_X%X+X-X-y.y_y%y+y+123@gmail.com => ('X.X_X%X+X-X', 'y.y_y%y+y', '123')
Add Comment
Please, Sign In to add comment