Regular Expressions Question.

Q

questionmarc420

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.

(e-mail address removed) <-- works

(e-mail address removed) <---- only (e-mail address removed) 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
 
Q

questionmarc420

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
 
Q

questionmarc420

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?
 
J

Joe Attardi

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).
 
Q

questionmarc420

thanks i forgot to remove the post cuz i had figured it out by my self.

tahnk you very mcuh anyways :D

-morc
 
O

Oliver Wong

Joe Attardi said:
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).

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
 
R

Roedy Green

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
 
O

Oliver Wong

Roedy Green said:
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

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
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top