开发者

[A-Z]{2,4} not limiting to between 2 & 4 characters

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 jim@f.com. 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 开发者_JS百科long, long night of learning regexes, in and out, and I'm trying to look badass. :)


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


Ruby regular expression documentation:

  • Ruby 1.8: http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp
  • Ruby 1.9: http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜