<?php
$tests = [
'foo',
'fooBar',
'foo123',
'123Foo',
'fooBar123',
'foo123Bar',
'123FooBar',
];
var_export(
preg_replace(
'/(?:\d++|[A-Za-z]?[a-z]++)\K(?!$)/',
'-',
$tests
)
);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array (
0 => 'foo',
1 => 'foo-Bar',
2 => 'foo-123',
3 => '123-Foo',
4 => 'foo-Bar-123',
5 => 'foo-123-Bar',
6 => '123-Foo-Bar',
)
preferences:
86.33 ms | 407 KiB | 5 Q