...

View Full Version : Quick Regex Help



benjam1nrk
03-11-2010, 04:55 AM
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:
if (preg_match("/^Subject: Periodic Bill for Order (.*) Approved/", $lines[$i], $matches)) {
$subject = $matches[1];
}

This works perfectly when the subject is:
Periodic Bill for Order 101745-123A672D1E8-6BB7D3B0-DD48335 Approved

But when the subject is:
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?

Ahri
03-11-2010, 02:13 PM
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:
101745-123A672D1E8-6BB7D3B0-DD48335
10.174.5.136-123A632D1E8-6AA7D3B0-DD48775

Conclusion: the regex is fine.

Perhaps you should paste in more code ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum