Help reading RegEx expression

M

Morten Snedker

In another thread I found this snippet for validating an e-mail:

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$


Would someone please help to read this? I don't get the slashes, dots,
plus'es etc.

I've been by
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconcharacterclasses.asp,
but still find it hard to read.

I suppose it's easy enough once you get the idea...but I'm still
clueless! :)


Regards /Snedker
 
L

Larry Lard

Morten said:
In another thread I found this snippet for validating an e-mail:

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$

I think this actually has a few bugs. This is what it matches:

<regex description>
One or more characters that are each a letter or a digit or _ or - or .

Then @

Then
Either [ followed by a 'dotted triple', being three 1 to 3 digit
numbers each followed by .
Or one or more instances of (a 'word' followed by .), where the 'word's
'letters' can be letters or digits or -

Then
Either 2 to 4 letters
Or a 1 to 3 digit number

Then optionally ]

Furthermore, there must be no characters in the string before or after
the characters that match the above pattern.
</regex description>

The bug? Well, presumably the intention is to allow the 'server' part
of the address to be either @[aaa.bbb.ccc.ddd] (with acceptable
numbers) or @word.anotherword.domain (with letters) - but as it stands,
all these things will be matched:

(e-mail address removed).123
(e-mail address removed).123]
[email protected]
user@[999.999.999.999
user@[999.999.999.999]

none of which look as if they will be valid.

But it's a sticky area to get in to, frankly, so I'm not gonna make too
much of a fuss :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top