Email address subtraction | SoloLearn: Learn to code for FREE!

+2

Email address subtraction

Can I use "([\w\.-]+)@([\w\.-]+)“ instead of "([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)“ I tried it, it seems to work well.

3/6/2018 2:21:13 PM

rightdragon

7 Answers

New Answer

+14

The last part is for capturing the "." (dot) Otherwise [email protected] 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 [email protected]

+1

Thanks for the detail. I got it. [email protected] 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 :).