Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Regex for capture two types of patterns [closed]
- XXXX-yyyyy+123131331@gmail.com
- XXXX+313131313@gmail
- /^w+(-w+)?+d+@S+$/
- ^ # the start of the string
- w+ # one or more ascii alhpa-nums
- ( # start group 1
- - # the literal '-'
- w+ # one or more ascii alhpa-nums
- )? # end group 1, and make it optional
- + # the literal '+'
- d+ # one or more digits
- @ # the literal '@'
- S+ # one or more non-space chars
- $ # the end of the string
- ^(w+)(?:-w+)?+d+@S+$
- /p{Lu}+(-p{Ll}+)?+d+@gmail.com/
- /([A-Z0-9._%-]+?)(?:-([A-Z0-9._%]+))?+(d+)@gmail.com/i
- p = re.compile(r"([A-Z0-9._%+-]+?)(?:-([A-Z0-9._%+]+))?+(d+)@gmail.com", re.IGNORECASE)
- m = p.search("XXXX-yyyy+123131313@gmail.com")
- m.groups()
- # ('XXXX', 'yyyy', '123131313')
- ( # start capture group 1
- [A-Z0-9._%+-] # match the characters in the []
- +? # one or more times, lazy
- ) # end capture group 1
- (?: # start non-capturing group
- - # match the literal character '-'
- ( # start capture group 2
- [A-Z0-9._%+] # match the characters in the []
- + # one or more times
- ) # end capture group 2
- )? # end non-capturing group, matching 1 or 0 times
- + # match the literal character '+'
- ( # start capture group 3
- d+ # match digits [0-9] one or more times
- ) # end capture group 3
- @gmail.com # match the literal characters '@gmail.com'
- 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