LiNUxG0d
12-06-2005, 06:37 PM
Hey all!
Language: PHP
I have a script that I'm creating to match a bunch of regex's (in a mail message with headers). I'm REALLY stumped on this one. I'm at a point where I'm trying to match IP's and it's giving me a heck-load of grief.
I've tried using Regex Coach as a debugging tool because I can't figure this out. I pasted my text (mail headers and message), pasted my regex and boom, they're all highlighting. When I run my preg_match_all($pattern, $message, $matches) in PHP though, it returns one match only.
Code snippet:
$pattern = "/\b(?:\d{1,3}\.){3}\d{1,3}\b/";
$message = implode("", file("./testmessage"));
preg_match_all($pattern, $message, $results);
print "The size of the resulting array is: ".sizeof($results) . "\n";
for ($i=0;$i<sizeof($results);$i++) {
print $results[0][$i]."\n";
}
Results, when run in shell:
The size of the resulting array is: 1
204.92.87.244
I know the list should be much longer as it's a mail header and there are quite a few in there.
I've also tried this expression, which returned SOME of the IPs, just not ALL of them... like, it stops after 5 found however again, Regex Coach finds them all:
$pattern = "/(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])/";
Can someone help? For some reason I can never get all my IPs matched and my regex's are crapping out. Any help would be much appreciated. :(
Let me know and thank you all so much for your time.
Warmest regards,
Jacob
P.S. I am aware Regex Coach is mostly for Perl (or so I was told) but I believe PCRE would be smart enough to work my simple expressions. :(
Language: PHP
I have a script that I'm creating to match a bunch of regex's (in a mail message with headers). I'm REALLY stumped on this one. I'm at a point where I'm trying to match IP's and it's giving me a heck-load of grief.
I've tried using Regex Coach as a debugging tool because I can't figure this out. I pasted my text (mail headers and message), pasted my regex and boom, they're all highlighting. When I run my preg_match_all($pattern, $message, $matches) in PHP though, it returns one match only.
Code snippet:
$pattern = "/\b(?:\d{1,3}\.){3}\d{1,3}\b/";
$message = implode("", file("./testmessage"));
preg_match_all($pattern, $message, $results);
print "The size of the resulting array is: ".sizeof($results) . "\n";
for ($i=0;$i<sizeof($results);$i++) {
print $results[0][$i]."\n";
}
Results, when run in shell:
The size of the resulting array is: 1
204.92.87.244
I know the list should be much longer as it's a mail header and there are quite a few in there.
I've also tried this expression, which returned SOME of the IPs, just not ALL of them... like, it stops after 5 found however again, Regex Coach finds them all:
$pattern = "/(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])/";
Can someone help? For some reason I can never get all my IPs matched and my regex's are crapping out. Any help would be much appreciated. :(
Let me know and thank you all so much for your time.
Warmest regards,
Jacob
P.S. I am aware Regex Coach is mostly for Perl (or so I was told) but I believe PCRE would be smart enough to work my simple expressions. :(
