Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    36
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Quick Regex Help

    Hello,

    I have a php regex match which is driving me insane.

    The code is parsing an incoming email for a certain string in the subject line, from which it is grabbing an identification string. My code is as follows:
    PHP Code:
     if (preg_match("/^Subject: Periodic Bill for Order (.*) Approved/"$lines[$i], $matches)) {     
                
    $subject $matches[1];
            } 
    This works perfectly when the subject is:
    Code:
    Periodic Bill for Order 101745-123A672D1E8-6BB7D3B0-DD48335 Approved
    But when the subject is:
    Code:
    Periodic Bill for Order 10.174.5.136-123A632D1E8-6AA7D3B0-DD48775 Approved
    nothing is returned as a match.

    Even with the periods removed from the subject, nothing is found.

    Am I missing something completely elementary?

  • #2
    New Coder
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts
    PHP Code:
    function foo($str) {
            if (
    preg_match("/^Subject: Periodic Bill for Order (.*) Approved/""Subject: $str"$matches)) {
                    echo 
    $matches[1]."\n";
            }
    }

    foo("Periodic Bill for Order 101745-123A672D1E8-6BB7D3B0-DD48335 Approved");
    foo("Periodic Bill for Order 10.174.5.136-123A632D1E8-6AA7D3B0-DD48775 Approved"); 
    Output:
    Code:
    101745-123A672D1E8-6BB7D3B0-DD48335
    10.174.5.136-123A632D1E8-6AA7D3B0-DD48775
    Conclusion: the regex is fine.

    Perhaps you should paste in more code
    Every PHP programmer of any skill level should set error_reporting(E_ALL); at the top of their scripts or in their php.ini


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •