General RegEx Pattern Help

Hey guys, this is my first post being brand new to the forums here. My apologies if I am in the wrong section.

I need help creating a simple regex pattern to store 5 IPs into 5 different variables. I think I need to use “preg_split” but I don’t know where to begin.

Here is an example of my file to be parsed.

1/27/2013 6:31:10 AM Removed        <89.155.107.178>
1/27/2013 6:31:17 AM Added          <77.122.41.208>
1/27/2013 6:31:18 AM Removed        <77.122.41.208>
1/27/2013 6:31:25 AM Added          <78.106.197.206>
1/27/2013 6:31:26 AM Removed        <78.106.197.206>

Thanks in advance!

Do you need only the IP address?

You would need to read the file line by line (see file() function)

Then you can match the IP address from each line. For example:

[php]
$str = “1/27/2013 6:31:10 AM Removed <89.155.107.178>”;
if (preg_match(’/<(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})>/’, $str, $parts)) {
var_dump($parts);
}
[/php]

Output:

array (size=2)
  0 => string '<89.155.107.178>' (length=16)
  1 => string '89.155.107.178' (length=14)
Sponsor our Newsletter | Privacy Policy | Terms of Service