How to I do a search for @anydomain.anyTLD using regular expressions?
1 Answer
@[a-zA-Z0-0\-]*\.[a-zA-Z\.]*
You could improve that but I don't think n++ deals with more complicated regex patterns.
Ideally we'd just use something like
/@[a-z0-9\-]\.[a-z\.\-]{1,40}/i
Which supports everything from the iana TLD list But N++ doesn't support that.
And if we want to get fancy we could do
(?:[a-z0-9!#$%&'*+/=?^_
{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
Which supports RFC2822 (see here for more details)
-
1
.co.uk
would like to speak to you, it's 4 characters. I've found that exact regex matching is often far more trouble than it's worth - for example with to. A more exact regex might miss it, but I was using(https?://[^\s]*)
, a much more general expression, and it worked fine.– PhoshiCommented Jun 8, 2010 at 20:21 -
You are most correct, I have changed the above to work with websites such as .co.uk. Commented Jun 8, 2010 at 20:30
-
1
-