+ 2
Email address subtraction
Can I use "([\w\.-]+)@([\w\.-]+)“ instead of "([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)“ I tried it, it seems to work well.
7 Antworten
+ 14
The last part is for capturing the "." (dot)
Otherwise hello@world is valid.
+ 6
Like Swapnil already mentioned, that last bit captures the TLD (top-level domain). Mind though, that some addresses may contain 2- or 3-level subdomains (or perhaps even more), so that last regex group has to check for one or more occurences.
+ 1
I think you can.
+ 1
Thank you for replying. So I do not understand why this tutorial explain "([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)“.
+ 1
It explains this regex, because this captures the ending (.com) in a single capture group. Your version also captures text like a@b
+ 1
Thanks for the detail. I got it. a@b is enough to grab email address, I think.
+ 1
I see. Thank you very much, Swapnil and Kuba! I just begun to learn programme, pythin is my first programming lunguage, so I cannot image examples. Now, I understand this question clearly. Thanks again :).