$re = '/((CAV-\d\s)[AGCT]+)(?:\n\2[AGCT]+)*/';
$str = 'CAV-1 ATCTACTTCTATCG
CAV-2 GCGCGTAGCTAGCT
CAV-2 AAGCGCTCGTAAAA
CAV-2 AAGCGCTCGTAAAA
CAV-2 AAGCGCTCGTAAAA
CAV-3 AAATATATATATCC';
$subst = "\1";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
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