0

I came up with the following

([\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})

I would also like to remove emails that start with a number or -. By remove I mean to select only the address and not to remove the entire match.

Is there a way to do that?

A.S.F Studio
  • 43
  • 1
  • 7
  • So that we know this isn't a duplicate, could you edit your question to clearly show which types of email addresses are valid and which are not? – Tim Biegeleisen Sep 26 '16 at 15:08
  • What language are you using? – Federico Piazza Sep 26 '16 at 15:09
  • 1
    Addresses starting with numbers are valid. I just created one with my convenient web application that allows users to easily create mail aliases: `650-039-8799@kylheku.com`. Please read the relevant RFC's, starting with 822, about what is valid e-mail syntax. About the only RFC feature you might think about rejecting is the use of comments. (Yes, e-mail addresses can contain comments, which is text enclosed in parentheses!) – Kaz Sep 26 '16 at 15:11

1 Answers1

0

^(?:\d+|-+)?([\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})$

This should do the trick. It'll capture emails but also filter out ones that start with a number or the - character and pulls the email from it.

ThePerplexedOne
  • 2,920
  • 15
  • 30
  • This will not match quite a few of the existing TLDs (like .weatherchannel, or .americanexpress) nor any internationalised TLD. – Vatine Sep 26 '16 at 15:25
  • Hey, first of all, thanks a lot. This will not work for me if I'll get an email like this 5644-865hadarikt@gmail.com or even like this 5644-865-765hadarikt@gmail.com. how can I make it to not select that initial sequence? Thanks – A.S.F Studio Sep 27 '16 at 06:24