I have a preg_replace that finds duplicate entries and consolidates. I need to take into consideration the dash as well, but currently it does not.
$id = KRS-KRS-123
preg_replace('/^(\w+)-(?=\1)/', '', $id);
// returns KRS-123
$id = KRS-KRS123
preg_replace('/^(\w+)-(?=\1)/', '', $id)
// returns KRS123
// I need this one to return KRS-KRS123
Add a word boundary,
\b, after the\1inside the look ahead(?=\1\b):That way, the lookahead will only evaluate to true if
\1is followed by a\W(a[^\w]) or the end-of-string.Demo
will produce: