<?php $tests = [ 'LocalBusiness' => 'Local Business', 'CivicStructureBuilding' => 'Civic Structure Building', 'getUserMobilePhoneNumber' => 'Get User Mobile Phone Number', 'bandGuitar1' => 'Band Guitar 1', 'band2Guitar123' => 'Band 2 Guitar 123', 'CustomerIDWithSomeOtherJETWords' => 'Customer ID With Some Other JET Words', 'noOneIsMightierThanI' => 'No One Is Mightier Than I', 'USAIsNumber14' => 'USA Is Number 14', '99LuftBallons' => '99 Luft Ballons', 'fillOutYour403EForm' => 'Fill Out Your 403 E Form', 'ABC123IsEasyAs' => 'ABC 123 Is Easy As', ]; $result = []; foreach ($tests as $input => $expected) { $newString = ucwords( preg_replace( '/(?: [A-Z]+? (?=\d|[A-Z][a-z]) #acronyms |[A-Z]?[a-z]+ (?=[^a-z]) #words |\d+ (?=\D) #numbers |(*SKIP)(*FAIL) #abort )\K /x', ' ', $input ) ); $result[] = ($newString === $expected ? 'PASSED' : 'FAILED') . ': "' . $newString . '"'; } var_export($result);
You have javascript disabled. You will not be able to edit any code.