Extract email and name with regex

后端 未结 5 2078
醉酒成梦
醉酒成梦 2020-12-06 02:10

What would be the regular expressions to extract the name and email from strings like these?

johndoe@example.com
John 
John Doe &l         


        
5条回答
  •  一整个雨季
    2020-12-06 02:37

    You can try this (same code as yours but improved), but you need to check returned groups after matching because the email is either returned in group 2 or group 3, depending on whether a name is given.

    (?:("?(?:.*)"?)\s)?<(.*@.*)>|(.*@.*)
    

提交回复
热议问题