Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. r'^email/(?P<email>[^@s]+@[^@s]+.[^@s]+)/$',
  2.  
  3. email/some_alphanumeric[A-Z0-9]_special_chars_@#$*some_alphanumeric_special_chars_#$*.some_alphanumeric_special_chars_#$*
  4.  
  5. myurl/email/blabla@blabla.com
  6.  
  7. myurl/email/([^@s]+@[^@s]+.[^@s]+)
  8.  
  9. # coding=utf8
  10. # the above tag defines encoding for this document and is for Python 2.x compatibility
  11.  
  12. import re
  13.  
  14. regex = r"myurl/email/([^@s]+@[^@s]+.[^@s]+)"
  15.  
  16. test_str = "myurl/email/blabla@blabla.com"
  17.  
  18. matches = re.finditer(regex, test_str, re.MULTILINE)
  19.  
  20. for matchNum, match in enumerate(matches, start=1):
  21.  
  22. print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
  23.  
  24. for groupNum in range(0, len(match.groups())):
  25. groupNum = groupNum + 1
  26.  
  27. print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
  28.  
  29. # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
  30.  
  31. r'^email/(?P<email>[^@s]+@[^@s]+.[^@s]+)/$'
  32.  
  33. email/ = consolent value in your url
  34.  
  35. [^@s] = you can write any character except @ and space "/s"
  36. @[^@s] = you must start with @ + anything expect @character and space "/s"
  37. . = matches "."
  38. [^@s] = you can write anycharacter except @ and space "/s"
  39. + = you can type many character
  40.  
  41. /$ = end of url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement