English 中文(简体)
[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 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).

问题回答

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.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签