Is there an easy regex that will find the most consecutive characters in a specified text file. For example, you have a text file with that contains 'aa' and later in the document it contains 'aaaa'. You would want to match 'aaaa' and not the 'aa'. Right now I have to do a loop thoughtout the text file and would like to do just one match:
$max = 0;
$copy = "something with consecutive letters aa and more consecutive letters aaaa";
while (preg_match("/[a]*(a+)([a]+)\1([a]+|$)/", $copy, $regs)){
if ($max < (strlen($regs[1]))) {
$max = strlen($regs[1]);
}
$regs[2] = preg_quote($regs[2], "/");
$copy = preg_replace("/$regs[1]$regs[2]$regs[1]/", "", $copy);
}
Is there an easy way than having to do the while loop?