regex extract email from strings

前端 未结 7 1469
陌清茗
陌清茗 2020-12-01 16:25

I want to know if by using regular expressions I am able to extract emails from the following strings?

The following RE pattern is .*@.*match with all st

7条回答
  •  伪装坚强ぢ
    2020-12-01 17:21

    You can use the following regex to capture all the email addresses.

    (?[\w.]+)\@(?\w+\.\w+)(\.\w+)?
    

    see demo / explanation

    additionally if you want, you can capture only those emails that contains a specific domain name (ie. some-url.com) and to achieve that you just need to replace the \w+\.\w+ part after with your desired domain name. so, it would be like (?[\w.]+)\@(?outlook.com)(\.\w+)?

    see demo / explanation

提交回复
热议问题