我在我的项目中使用Asp.Net/C#
。在我的一个表单中,我使用Regular Expression Validator
来验证电子邮件地址。我搜索了一些验证电子邮件的示例。我发现了{{1} }
任何人都可以向我解释这种模式,它会非常有用。
非常感谢任何解释。
感谢。
答案 0 :(得分:2)
一些简短的提示:
\ w代表单词字符
[ - +。']为大括号中的一个字符
plus和*是量词
()包围一个可以创建反向引用的组(您可以引用或以编程方式读取的内容)
更长(自动)的解释:
\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/