Page 1 of 1

Matching an email with a port number

Posted: Thu Jul 22, 2004 10:39 am
by evilmonkey
Hello. I have a regular expression (pretty good one I might add), but it has one downfall: it does not match a port number, in fact, it negates the whole email if there is a port number. Eg, it will match "admin@vagonweb.com", but not "admin@vagonweb.com:25". How can I add that support? Mind, the port is very optional, and I want it to match the string even if I have no port. Here's the regular expression:

Code: Select all

їa-zA-Z]ї\w\.-]*їa-zA-Z0-9]@їa-zA-Z0-9]ї\w\.-]*їa-zA-Z0-9]\.їa-zA-Z]їa-zA-Z\.]*їa-zA-Z]
Thanks!

Posted: Thu Jul 22, 2004 10:47 am
by feyd
untested

Code: Select all

^їa-zA-Z0-9_.-]+@(їa-zA-Z0-9_-]+\.)+їa-zA-Z]{2,4}(:(ї0-5]ї0-9]{4}|6ї0-4]ї0-9]{3}|65ї0-4]ї0-9]{2}|655ї0-2]ї0-9]|6553ї0-5]|ї0-9]{1,4}|ї0-9a-fA-F]{4}))?$
Course, this only covers romanized domain-names...

[edit: made a tweak for the port restriction.]

Posted: Thu Jul 22, 2004 10:55 am
by evilmonkey
romanized?

Your expresseion works, you just missed a closing bracket ")". Here is is, in working order:

Code: Select all

^їa-zA-Z0-9_.-]+@(їa-zA-Z0-9_-]+\.)+їa-zA-Z]{2,4}(:(ї0-9]{1,5})|ї0-9a-fA-F]{4})?$
Thanks :)

Posted: Thu Jul 22, 2004 11:02 am
by feyd
:oops: you actually placed the right paren in slightly wrong place, I corrected mine.. still untested though.. :)

Posted: Thu Jul 22, 2004 11:08 am
by evilmonkey
Whoa, that's complicated...thanks feyd!

Posted: Thu Jul 22, 2004 11:12 am
by feyd
yeah.. I thought about it for a bit.. and had to impose the port numbering restrictions.. although it may need to go to 65536, hmm... According to this [auditmypc.com] the range is 0-65535.. ok. :)