RobertP Posted June 27, 2012 Share Posted June 27, 2012 i am in need of a regular expression that will parse my associative array keys into clean strings. example: testKeyString33 = Test Key String 33 dbHost = Db Host simpleStringWithMore = Simple String With More This is how i think it would work... - append a space to all UPPER CASE letters (aSd = a Sd) - append a space to the start of all integers... (asd123 = asd 123) if this is confusing at all, please say so :S Link to comment https://forums.phpfreaks.com/topic/264847-preg-replace/ Share on other sites More sharing options...
.josh Posted June 27, 2012 Share Posted June 27, 2012 $string = "abc123AbcDef"; $string = preg_replace('~(?<!^)([A-Z]|[0-9]+)~',' $1',$string); output: abc 123 Abc Def Link to comment https://forums.phpfreaks.com/topic/264847-preg-replace/#findComment-1357406 Share on other sites More sharing options...
RobertP Posted June 27, 2012 Author Share Posted June 27, 2012 what does this mean? positive look-ahead? (?<!^) Link to comment https://forums.phpfreaks.com/topic/264847-preg-replace/#findComment-1357433 Share on other sites More sharing options...
.josh Posted June 27, 2012 Share Posted June 27, 2012 no, it's a negative look-behind. It checks to see if the character it is looking for isn't at the start of the string, by looking at the character that comes before it (the ^ signifies start of string, which isn't an actual character, but you get the idea). Otherwise, you will end up with for instance "Abc" to " Abc" Link to comment https://forums.phpfreaks.com/topic/264847-preg-replace/#findComment-1357482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.