有关特定正则表达式模式的说明

本文关键字:模式 说明 正则表达式 | 更新日期: 2023-09-27 18:32:48

我在项目中使用Asp.Net/C#。在我的一个表格中,我正在使用Regular Expression Validator来验证电子邮件地址。我搜索了一些验证电子邮件的示例。我找到了这个'w+([-+.']'w+)*@'w+([-.]'w+)*'.'w+([-.]'w+)* 谁能解释一下这种模式,这将非常有帮助。任何解释都非常感谢。

谢谢。

有关特定正则表达式模式的说明

一些简短的提示:

  • ''w 代表 单词字符

  • [-+.'] 表示大括号中的字符之一

  • 加号和 * 是量词

  • ( ) 围绕一个可以创建反向引用的组(您可以以编程方式引用或阅读的内容)

更长的(自动)解释:

'w+([-+.']'w+)*@'w+([-.]'w+)*'.'w+([-.]'w+)*
Match a single character that is a “word character” (letters, digits, and underscores)     «'w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 1 «([-+.']'w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last  iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-+.'” «[-+.']»
   Match a single character that is a “word character” (letters, digits, and underscores) «'w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “@” literally «@»
Match a single character that is a “word character” (letters, digits, and underscores) «'w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 2 «([-.]'w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-.” «[-.]»
   Match a single character that is a “word character” (letters, digits, and underscores) «'w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “.” literally «'.»
Match a single character that is a “word character” (letters, digits, and underscores) «'w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 3 «([-.]'w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-.” «[-.]»
   Match a single character that is a “word character” (letters, digits, and underscores) «'w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

我使用RegexBuddy创建了更长的自动解释

编辑:

要获得有关正则表达式的一些入门信息,您可以查看 http://www.regular-expressions.info/