$re = '/^(\w+?)$\n^(?=\1\:\w+?)/m';
$str = 'db_unknown
cdbm01
oec0005u1
oec0008q1
oec0009q1
oec0015q1
oec0016q1
oec0205q1
oec0206q1
oec0209q1
oec0217q1
oec0218q1
oec0222q1
oec0224q1
oec0225q1
oec0282q1
oec0355q1
oec0374q1
oec0385q1
oec0388q1
oec0409q1
oec0419q1
oec0420q1
cdbm01
oec0005u1
oec0008q1
oec0009q1
oec0015q1
oec0016q1
oec0206q1
oec0209q1
oec0225q1
oec0374q1
oec0385q1
oec0388q1
oec0409q1
oekngtest1
oec0355q1
oec0462q2
oec0463q2
oec0464q2
oec0482q2
oec0496q2
oec0497q2
oec0499q2
oec0506q2
oec0511q2
oec0519q2
oec0529q2
oec0547q2
oec0553q2
oec0555q2
oec0667q2
oec0670q2
db1db2
db1db2
oec0462q2
oec0463q2
oec0464q2
oec0482q2
oec0496q2
oec0497q2
oec0499q2
oec0506q2
oec0511q2
oec0519q2
oec0529q2
oec0547q2
oec0553q2
oec0555q2
oec0667q2
oec0670q2
';
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