javascript - Regex in JS to find first characters of each word and cast to Uppercase -
i looking regular look in javascript help me homecoming first characters of each word in uppercase:
"to string" => "tds"
most of import part homecoming new string old.
easy, 2 functions:
result = subject.replace(/\b[a-z]+\s*/g, "").touppercase(); in demo, @ substitutions @ bottom. that's effect of regex replacement before touppercase()
how works
\b matches position not word boundary, in other words, spot between 2 letters. [a-z]+ matches many letters possible \s* matches optional spaces we replace empty string we convert upper case javascript regex
No comments:
Post a Comment