Extracting an email from a string

Trying to extract an email from a string.

I have tried

publicfinal String rx_email ="[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}";

Pattern pattern = Pattern.compile( rx_email, Pattern.DOTALL );

String sRecptMessage = read();

System.out.println("sRecptMessage: " + sRecptMessage );

Matcher matcher = pattern.matcher( sRecptMessage );

while( matcher.find() ){

String to_email = matcher.group( 1 );

System.out.println("to_email: " + to_email );

}

The code is not matching the email address in the string.

Is this a problem with the reg expression or something else.

Regards

[881 byte] By [jayclarkea] at [2007-10-2 16:10:26]
# 1
First and foremost, there is a problem with your problem description.
CeciNEstPasUnProgrammeura at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 2
Please give an example of a String that should work.
CeciNEstPasUnProgrammeura at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 3
The string sRecptMessage will likeRCPT TO:<aname@adomain.com>
jayclarkea at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 4
> The string sRecptMessage will like> RCPT TO:<aname@adomain.com>Why are you in that case only allowing upper case characters in your regexp?Kaj
kajbja at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 5
It will work better if you change your regexp to:String rx_email = "[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}";and you should print group 0, and not 1.(But it still think that the expression is a bit odd)Kaj
kajbja at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 6
s/it/I
kajbja at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 7
Notwithstanding what else has been said, you'd better escape the dot that stands alone.
da.futta at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 8
I'd suggest research if not already: http://www.google.com/search?hl=en&q=email+address+regular+expressionAnd wouldn't the dot (.) need to be escaped? So where that character is, I believe you'd need \. instead to match a dot.
warnerjaa at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...
# 9

> I'd suggest research if not already:

> http://www.google.com/search?hl=en&q=email+address+reg

> ular+expression

>

> And wouldn't the dot (.) need to be escaped? So where

> that character is, I believe you'd need \. instead to

> match a dot.

Oh yeah, and then since \ means something in string literals as well, you'd need to specify "\\." to get the regular expression to see it as "\.".

warnerjaa at 2007-7-13 16:54:27 > top of Java-index,Java Essentials,Java Programming...