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!
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;
}
}
preg_match_all('/test\\d+:(?!OK)/', $allrows, $rowsNotOk)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.