[AZ]{2,4}不限于2与1之间。 4 个字符

发布于 2024-08-15 15:11:45 字数 684 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁憨憨 2024-08-22 15:11:45

确实如此,但它仅适用于顶级域名(示例中的“com”)。

It does, but it's only applied to the top-level domain name (the "com" in your example).

不即不离 2024-08-22 15:11:45

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文