使用正则表达式选择有效的电子邮件地址

时间:2016-09-26 15:06:09

标签: regex validation

我想出了以下

<body>
  <div class="flex">
    <div>orange box and aqua box need to take up one row together</div>
    <div>Hellothis is a long test sentence this is a long test sentence this is a long test sentence this is a long test is a long test sentence this is a long test sentence this is a long test sentence this is a long test</div>
    <div>Hello 2this is a long test sentence this is a</div>
    <div class="hi">Get me closer to Mr. Orange</div>
  </div>
</body>

我还要删除以数字或 - 开头的电子邮件。删除我的意思是只选择地址而不是删除整个匹配。

有办法吗?

1 个答案:

答案 0 :(得分:0)

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

这应该可以解决问题。它会捕获电子邮件,但也会过滤掉以数字或-字符开头的电子邮件,并从中提取电子邮件。

相关问题