Create regex for preg_patch function of php

Discussion in 'PHP' started by xpertdev, Nov 14, 2010.

  1. #1
    Actually I am doing code to find the bounced mail. I am placing the source code of the full email to match. one of my email giving above error. So I need to check for that error contain in email code or not. If that code found then it will return error accordingly. So in that error message dynamic parts are email address, ip in square brackets and the string mailbox unavailable.

    The string I need to find is as below, dynamic portion are covered in bold text:
    The mail system

    <aaa@asg.com>: host mx2.hotmail.com[65.55.92.152] said: 550
    Requested action not taken: mailbox unavailable (in reply to RCPT TO
    command)

    So first it check for email address like <demo@email.com>, then for IP address like [12.25.65.85] and then a string "mailbox unavailable". Order must be this.
     
    xpertdev, Nov 14, 2010 IP
  2. d_s

    d_s Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can get the individual parts from regexlib.com and then join them using a + so that one or more matches are pointed out.

    regards,
    d_s.
     
    d_s, Nov 15, 2010 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    Use this regex:

    
    preg_match('/<aaa@asg\.com>.*\[65\.55\.92\.152\].*mailbox unavailable.*/Uism',$content);
    
    PHP:
    Just make sure you always escape the periods and brackets.
     
    ThePHPMaster, Nov 15, 2010 IP
  4. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @PHPMaster

    can you let me know, what if i want the regexp for IP address also rather than static IP you have mentioned.
    and what the Uism will do here?
     
    xpertdev, Nov 15, 2010 IP
  5. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    also I need email address to be dynamic, how can I do this?
     
    xpertdev, Nov 15, 2010 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    ThePHPMaster, Nov 16, 2010 IP