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


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


7 Answers

New Answer


The last part is for capturing the "." (dot) Otherwise [email protected] is valid.


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.


I think you can.


Thank you for replying. So I do not understand why this tutorial explain "([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)“.


It explains this regex, because this captures the ending (.com) in a single capture group. Your version also captures text like [email protected]


Thanks for the detail. I got it. [email protected] is enough to grab email address, I think.


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 :).