2
votes

I need to wright regex using preg_match in PHP to do next:

I do have string like this:

test1:OK
test2:OK
test3:FAILD
test4:PROGRESS
test5:OK

so I need to find rows which are no OK..
test3:FAILD
test4:PROGRESS

so I think I have to check string between : and \r\n (\n) if != OK, how do I do this using preg_match?

Help much appreciated!

2

2 Answers

1
votes

Why use regex? String functions should be just fine for this; regexs are more of a last resort.

$lines = explode("\n", str_replace("\r\n", "\n", $lines));
$failed = array();

foreach ($lines as $line) {
    if (strpos($line, 'OK') === false) {
        $failed[] = $line;
    }
}
1
votes

preg_match_all('/test\d+:(?!OK)/', $allrows, $rowsNotOk)