捕获具有替代字符或模式的电子邮件地址



我有一些用户帖子需要尝试删除其中的电子邮件地址。人们一直在试图绕过我的简单正则表达式,所以我正试图找到一个解决方案。任何修改以下内容的帮助都会很有帮助。

https://rubular.com/r/B2rzST2u39fjDm

模式将是

a word made of any of these characters: [a-z0-9!#$%&'*+/=?^_`{|}~-]
followed by an @ sign, or the word "At" or " at " in lower case or upper case, surrounded by 0-4 spaces.
followed by another word of these characters ([a-z0-9]
followed by a "." or "dot", " Dot ", "D0T" in lower case or upper case, surrounded by 0-4 spaces.
followed by any 2-3 of these characters [a-z]

RegEx应不区分大小写。

我的正则表达式缺少一些项,特别是带有前缀的域。

阅读需求,一个选项可以是在最后一部分之前添加一个重复组。

[a-z0-9!#$%&'*+/=?^_`{|}~-]+s{0,4}(?:@|at)s{0,4}[a-z0-9]+s{0,4}(?:(?:.|dot)[a-z0-9]+s{0,4})*(?:.|dot)s{0,4}[a-z]{2,3}

零件将匹配:

  • [a-z0-9!#$%&'*+/=?^_`{|}~-]+重复列出的内容1次以上
  • s{0,4}匹配0-4个空白字符
  • (?:@|at)匹配@at
  • s{0,4}匹配0-4个空白字符
  • [a-z0-9]+匹配a-z或0-9范围内的字符1+次
  • s{0,4}匹配0-4个空白字符
  • (?:非捕获组
    • (?:.|dot)[a-z0-9]+s{0,4}
  • )*关闭群组并重复0+次
  • (?:.|dot)匹配.dot
  • s{0,4}[a-z]{2,3}匹配0-4个空白字符和a-z范围内字符的2或3倍

Rubular演示(正如@Wiktor Stribiżew所指出的,你不需要m修饰符(

最新更新