$re = '/^(?<good>\b(?:\w+\.)*(?:alsogood|good)\.com(?::\w+)?\b)(?: +\g<good>)*$/m';
$str = 'test.good.com:3 great.alsogood.com:latest test2.good.com
foo.bar.good.com:1
I would like it to match the previous strings but not match something like these:
test.good.com:3 another.bad.com great.good.com
foo.bad.com:1';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php