$1
works on the right side (rewrite), but not in the regex. You need to use \1
.
Try:
RewriteRule ^(.)([a-z]+)\1([a-z]+) $2-$3
I ran into a bizarre edge case with the *
where it split based on the second character of the string, and not the second. XtestingXtest
resulted in es-ing
... so yeah, not sure what was happening there. If I use a +
it works fine.
Also, since *
and +
are greedy, if you have multiple delimiter characters, it will split on the last occurrence of the character:
XbaseXtest -> base-test
XbaseXteXst -> baseXte-st
XbaseXtestX -> baseXtest-