I created this regexp that will add an underscore infront of all capital letters except for the first one if it's in the beginning of the string
$string = preg_replace('/(?!^)[A-Z]/', '_$0', $string);
// Hello --> Hello
// HelloHello --> Hello_Hello
// aHelloHello --> a_Hello_Hello
// HELLO --> H_E_L_L_O
// hello --> hello
// HHEllo --> H_Hello
I would like the regexp to skip all continuous capital characters at the beginning of the string:
// HHello --> HHello
// HEllO --> HEll_O
// aHEllo --> a_H_Ello
// HHHHHHHHHHellO --> HHHHHHHHHHell_O
In short: a regexp that adds an underscore infront of all capital letters but ignores all continuous capital letters from the beginning of the string.