[AZ]{2,4}不限于2与1之间。 4 个字符
PCRE: /\A[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[a-z]{2,4}|museum|travel)\z/i
POSIX: /^[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i
这个正则表达式在各个方面都满足我的需求,除了它允许诸如 [email protected ]。它说这些是匹配的。如果我没记错的话,[AZ]后面的{2,4}不是意味着它必须在2到4个字符之间吗?会不会是争吵、博物馆和旅行的问题?我已经验证这些在我的应用程序中是允许通过的,还有一些正则表达式测试人员。 另外,我不清楚我是否正确执行了 PCRE 和 POSIX。我担心他们可能都是PCRE,我太可笑了。 AFAIK,JavaScript 是 POSIX,Ruby 是 PCRE。所以,如果我没有做到这一点,请让我轻松下来,这是学习正则表达式的一个漫长而漫长的夜晚,进进出出,我试图让自己看起来很糟糕。 :)
PCRE: /\A[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[a-z]{2,4}|museum|travel)\z/i
POSIX: /^[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i
This regex is correct in every way for my needs except that it allows emails such as [email protected]. It says these are a match. If I'm not mistaken, doesn't the {2,4} after [A-Z] mean that it has to be between 2 and 4 characters? Could it be a problem with the altercation and museum and travel? I have verified that these are allowed through in my application, and a few regex testers. Also, I'm fuzzy on whether I did do the PCRE and POSIX correctly. I fear they might both just be PCRE and I'm being ridiculous. AFAIK, JavaScript is POSIX and Ruby is PCRE. So if I didn't get that right, lemme down easy, it has been a long, long night of learning regexes, in and out, and I'm trying to look badass. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确实如此,但它仅适用于顶级域名(示例中的“com”)。
It does, but it's only applied to the top-level domain name (the "com" in your example).
Ruby 正则表达式文档:
Ruby regular expression documentation:
POSIX 不支持非捕获组
(?:group)
因此您的正则表达式都不是 POSIX。 JavaScript 不使用 POSIX。 JavaScript 正则表达式是 Perl 风格的,但它不具备所有功能。有关详细信息,请查看我网站上的正则表达式风格比较。POSIX does not support non-capturing groups
(?:group)
so neither of your regexes are POSIX. JavaScript does not use POSIX. JavaScript regular expressions are Perl-style but it doesn't have all the features. Check the regex flavor comparison on my site for details.