How To Use Regular Expressions To Insert Space Into A Camel Case String
I am using the following regular expression to insert spaces into a camel-case string var regex = /([A-Z])([A-Z])([a-z])|([a-z])([A-Z])/g; Example usage var str = 'CSVFilesAreCool
Solution 1:
Try this regex and replace using positive look-ahead:
var regex =/([^A-Za-z0-9\.\$])|([A-Z])(?=[A-Z][a-z])|([^\-\$\.0-9])(?=\$?[0-9]+(?:\.[0-9]+)?)|([0-9])(?=[^\.0-9])|([a-z])(?=[A-Z])/g;
var str ="CSVFilesAreCool123B--utTXTFoo12T&XTRules$123.99BAz";
str = str.replace(regex, '$2$3$4$5 ');
// CSV Files Are Cool 123 B ut TXT Foo 12 T XT Rules $123.99 B Az
(RegExr)
Post a Comment for "How To Use Regular Expressions To Insert Space Into A Camel Case String"