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 Quote Link to comment 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 Quote Link to comment 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? (?<!^) Quote Link to comment 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" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.