Re: Help a newbie

Kevin Rodgers <[email protected]> Tue, 14 Dec 2004 09:46:50 -0700
Newsgroups gmane.comp.jakarta.regexp.user
Message-ID <[email protected]>
[email protected] writes:
> I am changing a system developed by other company.
> 
> This system uses Jakarta Regexp to validate a e-mail. Now I need to change
> this to alow a e-mail address like this [email protected]
> 
> Actual Regexp : "^\w+(\.\w+)*(\_\w+)*@\w+(\_\w+)*(\.\w+)+(\_\w+)*$"
> 
> I am trying this but not works:
> "^\w+(\.\w+)*(\-+)*(\_\w+)*@\w+(\_\w+)*(\-+)*(\.\w+)+(\_\w+)*$"
> 
> Could you help me ??

See http://jakarta.apache.org/regexp/apidocs/

_ (underscore) is not a metacharacter and doesn't need to be escaped
with \ (backslash).  And \w matches underscore as well as letters and
digits.  So the original regexp should probably be:

	^\w+(\.\w+)*@\w+(\.\w+)*$

You want to allow - (hyphen) as well as underscore and alphanumeric
characters within words, so just change \w to (\w|-):

	^(\w|-)+(\.(\w|-)+)*@(\w|-)+(\.(\w|-)+)*$

-- 
Kevin Rodgers