Topic awaiting preservation: Splitting Caps in PHP with Regex |
|
---|---|
Author | Thread |
Obsessive-Compulsive (I) Inmate From: |
posted 01-28-2006 09:03
It's an odd question, but I have an XML file I'm parsing where each node name follows the convention of "PuttingNoSpacesInFrontOfCaps". So, is there a way using ereg or preg to find each match of "[a-z][A-Z]" and split them with a space? I've tried preg_replace(), but it replaces the characters as well, leaving me with "Puttin pace ront aps" (not a viable solution). |
Maniac (V) Mad Scientist From: :morF |
posted 01-28-2006 11:06
What you need to use, as far as I can see, is php->preg_split instead. |
Paranoid (IV) Inmate From: Norway |
posted 01-28-2006 11:17
Back references |
Paranoid (IV) Mad Scientist with Finglongers From: Germany |
posted 01-28-2006 11:54
If I remember php->preg_split correctly, |
Nervous Wreck (II) Inmate From: |
posted 01-28-2006 22:56
Thanks all. I was so fixated on the preceding lowercase letter I didn't consider other solutions. I certainly appreciate the help. |
Nervous Wreck (II) Inmate From: |
posted 01-30-2006 01:53
FYI, preg_split() suffers the same problem as preg_replace(). code: $labelArray = preg_split("/([A-Z]+[^A-Z]*)/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); $label = implode(" ", $labelArray);
|