Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Regular Expressions Question.

Thread view: 
questionmarc420@msn.com - 23 Jan 2006 17:16 GMT
hi,
ok i have ap eice of code which turns emaill addys into clickable
links. heres the code.

data_body = data_body.replaceAll("([a-zA-Z_0-9]++@)[^\\s<]+", "<A
HREF=\"mailto:$0\">$0</a>");

the code works fine.. itll search the string for an addy and itll work.
however if ther is a "." or an underscore the link stops there.

asfd@hotmail.com <-- works

as_df@hotmail.com <---- only df@hotmail.com works

I've been frustrated trying to find out how to add the punctuation in
this reg exp but im lost.

If someone can help please do
thanks
morc
questionmarc420@msn.com - 23 Jan 2006 17:28 GMT
my mistake i didn't realise google. turned the addys into "..."

the first one is asdf @ hotmail . com <---------------works fine
the second one is as_df @ hotmail. com <---------- link gets cut off,
only df @ hot mail. com is highlighted
questionmarc420@msn.com - 23 Jan 2006 17:41 GMT
sorry my mistake again
underscores work fine
iits when there is a period in the addy that it cuts off. ANyone know
how i can fix this?
Roedy Green - 23 Jan 2006 20:46 GMT
>sorry my mistake again
>underscores work fine
>iits when there is a period in the addy that it cuts off. ANyone know
>how i can fix this?

see http://mindprod.com/jgloss/newsreader.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Joe Attardi - 23 Jan 2006 18:01 GMT
> data_body = data_body.replaceAll("([a-zA-Z_0-9]++@)[^\\s<]+", "<A
> HREF=\"mailto:$0\">$0</a>");
> however if ther is a "." or an underscore the link stops there.

Well, you don't have a period listed as one of the characters in the
first part of your regex, so of course it won't match.

You need:
[a-zA-Z_.0-9] (note the inclusion of the period).
questionmarc420@msn.com - 23 Jan 2006 18:28 GMT
thanks i forgot to remove the post cuz i had figured it out by my self.

tahnk you very mcuh anyways :D

-morc
Oliver Wong - 23 Jan 2006 20:24 GMT
>> data_body = data_body.replaceAll("([a-zA-Z_0-9]++@)[^\\s<]+", "<A
>> HREF=\"mailto:$0\">$0</a>");
[quoted text clipped - 5 lines]
> You need:
> [a-zA-Z_.0-9] (note the inclusion of the period).

   Note that the regular expression will accept email addresses like .@. or
a@@ and other things that are obviously not valid e-mail addresses.

   Recognizing e-mail addresses via regular expressions is actually
relatively difficult to get right, but also a common enough feature that
someone has already solved the problem for you.

   Here's the regular expression for recognizing an e-mail address:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

   - Oliver
Roedy Green - 23 Jan 2006 20:58 GMT
>    Recognizing e-mail addresses via regular expressions is actually
>relatively difficult to get right, but also a common enough feature that
>someone has already solved the problem for you.

See the code for Bulk that assign a plausibilty number to an email
address.  The actual standard permits all sorts of things that are
most  likely errors.  

See http://mindprod.com/products1.html#BULK
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Oliver Wong - 23 Jan 2006 22:13 GMT
>>    Recognizing e-mail addresses via regular expressions is actually
>>relatively difficult to get right, but also a common enough feature that
[quoted text clipped - 5 lines]
>
> See http://mindprod.com/products1.html#BULK

   Out of curiosity, why do you not accept "military use" for your bulk
e-mailing program? Or is that a standard restriction you place against all
your software?

   - Oliver
Roedy Green - 23 Jan 2006 22:32 GMT
>    Out of curiosity, why do you not accept "military use" for your bulk
>e-mailing program? Or is that a standard restriction you place against all
>your software?

see http://mindprod.com/contact/roedy.html#NONMILITARY
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.