Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Regular Expressions Question.

Reply
Thread Tools

Regular Expressions Question.

 
 
questionmarc420@msn.com
Guest
Posts: n/a
 
      01-23-2006
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.

http://www.velocityreviews.com/forums/(E-Mail Removed) <-- works

(E-Mail Removed) <---- only (E-Mail 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

 
Reply With Quote
 
 
 
 
questionmarc420@msn.com
Guest
Posts: n/a
 
      01-23-2006
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

 
Reply With Quote
 
 
 
 
questionmarc420@msn.com
Guest
Posts: n/a
 
      01-23-2006
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?

 
Reply With Quote
 
Joe Attardi
Guest
Posts: n/a
 
      01-23-2006
> 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).

 
Reply With Quote
 
questionmarc420@msn.com
Guest
Posts: n/a
 
      01-23-2006
thanks i forgot to remove the post cuz i had figured it out by my self.

tahnk you very mcuh anyways

-morc

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      01-23-2006

"Joe Attardi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>> 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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-23-2006
On 23 Jan 2006 09:41:23 -0800, (E-Mail Removed) wrote, quoted
or indirectly quoted someone who said :

>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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-23-2006
On Mon, 23 Jan 2006 20:24:05 GMT, "Oliver Wong" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

> 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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      01-23-2006

"Roedy Green" <(E-Mail Removed) > wrote in
message news:(E-Mail Removed)...
> On Mon, 23 Jan 2006 20:24:05 GMT, "Oliver Wong" <(E-Mail Removed)>
> wrote, quoted or indirectly quoted someone who said :
>
>> 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


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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-23-2006
On Mon, 23 Jan 2006 22:13:25 GMT, "Oliver Wong" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

> 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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Regular Expressions in ASP.net Jay Douglas ASP .Net 3 11-03-2003 08:09 PM
Regular expressions mark Perl 4 10-28-2003 12:37 PM
perl regular expressions return last matched occurence? Dustin D. Perl 1 08-28-2003 01:51 AM
matching curly braces and regular expressions Dustin D. Perl 0 08-26-2003 11:18 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments