Regular Expressions Question.

Discussion in 'Java' started by questionmarc420@msn.com, Jan 23, 2006.

  1. Guest

    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.

    <-- works

    <---- only 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
     
    , Jan 23, 2006
    #1
    1. Advertising

  2. Guest

    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
     
    , Jan 23, 2006
    #2
    1. Advertising

  3. Guest

    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?
     
    , Jan 23, 2006
    #3
  4. Joe Attardi Guest

    > 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).
     
    Joe Attardi, Jan 23, 2006
    #4
  5. Guest

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

    tahnk you very mcuh anyways :D

    -morc
     
    , Jan 23, 2006
    #5
  6. Oliver Wong Guest

    "Joe Attardi" <> wrote in message
    news:...
    >> 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
     
    Oliver Wong, Jan 23, 2006
    #6
  7. Roedy Green Guest

    On 23 Jan 2006 09:41:23 -0800, 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.
     
    Roedy Green, Jan 23, 2006
    #7
  8. Roedy Green Guest

    On Mon, 23 Jan 2006 20:24:05 GMT, "Oliver Wong" <>
    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.
     
    Roedy Green, Jan 23, 2006
    #8
  9. Oliver Wong Guest

    "Roedy Green" <> wrote in
    message news:...
    > On Mon, 23 Jan 2006 20:24:05 GMT, "Oliver Wong" <>
    > 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
     
    Oliver Wong, Jan 23, 2006
    #9
  10. Roedy Green Guest

    On Mon, 23 Jan 2006 22:13:25 GMT, "Oliver Wong" <>
    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.
     
    Roedy Green, Jan 23, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas
    Replies:
    0
    Views:
    627
    Jay Douglas
    Aug 15, 2003
  2. ASP.Confused

    Question on regular expressions

    ASP.Confused, Jul 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    387
    ASP.Confused
    Jul 26, 2004
  3. jeffM
    Replies:
    3
    Views:
    393
    Alan Moore
    Feb 2, 2004
  4. Fred Smith
    Replies:
    1
    Views:
    983
    Martin Honnen
    Feb 5, 2004
  5. Noman Shapiro
    Replies:
    0
    Views:
    245
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page