Regular Expression Help

Discussion in 'PHP' started by rajesh_, Sep 8, 2007.

  1. #1
    Hi,
    I have one newsletter script which is having following line

    preg_match_all('/(\w+@\w+(?:\.\w+)+)/', $data, $array);

    if data is like

    Its taking only

    I think its removing dots also from data which is not desirable. Can you please change the regular expression so that dots are allowed. I am newbie to regular expression .
     
    rajesh_, Sep 8, 2007 IP
  2. rajesh_

    rajesh_ Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #2
    any help please?
     
    rajesh_, Sep 8, 2007 IP
  3. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #3
    Yes . in the email address is creating problem, search for
     
    it career, Sep 8, 2007 IP
  4. rajesh_

    rajesh_ Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    can you please tell How to fix?
     
    rajesh_, Sep 8, 2007 IP
  5. k2pi

    k2pi Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try to change the first w+ on your rule whith [0-9a-ZA-Z\.\-]+
     
    k2pi, Sep 9, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    The \w matches all alphanumeric characters and under scores, so no need to replace it. :) You can just add the \.\- to it.
     
    nico_swd, Sep 9, 2007 IP
  7. omgitsfletch

    omgitsfletch Well-Known Member

    Messages:
    1,222
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    145
    #7
    preg_match_all('/(\w+(?:\.\w+)+@\w+(?:\.\w+)+)/', $data, $array);

    Something like that oughta do it, right? Just adding the optional dot and optional second string after the dot like after the @ sign.
     
    omgitsfletch, Sep 9, 2007 IP