jquery - Split Pascal Case in Javascript (Certain Case) -
i've been trying javascript regex command turn eydlessthan5days eyd less 5 days. ideas?
the code used :
"eydlessthan5days" .replace(/([a-z])/g, ' $1') .replace(/^./, function(str){ homecoming str.touppercase(); });
out: e y d less than5 days still give me wrong result.
please help me. thanks.
try next function, it's made work kinds of strings can throw @ it. if find defects please point out in comments.
class="snippet-code-js lang-js prettyprint-override">function camelpad(str){ homecoming str // long acronyms , filter out lastly letter .replace(/([a-z]+)([a-z])/g, ' $1 $2') // lower-case letters followed upper-case letters .replace(/([a-z\d])([a-z])/g, '$1 $2') // lower-case letters followed numbers .replace(/([a-za-z])(\d)/g, '$1 $2') .replace(/^./, function(str){ homecoming str.touppercase(); }) // remove white space left around word .trim(); } // test cases document.body.appendchild(document.createtextnode(camelpad("eydlessthan5days"))); document.body.appendchild(document.createelement('br')); document.body.appendchild(document.createtextnode(camelpad("lolalldayfrom10to9"))); document.body.appendchild(document.createelement('br')); document.body.appendchild(document.createtextnode(camelpad("iliketostayuptil9o'clock"))); document.body.appendchild(document.createelement('br')); document.body.appendchild(document.createtextnode(camelpad("whatryoudoing?")));
javascript jquery string
No comments:
Post a Comment