Generate abbreviation from string in JavaScript using regular expressions?
3 answers
Adapting my answer from Converting a string to a correct file with javascript (which provides some test cases as well):
var toMatch = "hyper text markup language";
var result = toMatch.replace(/(\w)\w*\W*/g, function (_, i) {
return i.toUpperCase();
}
)
alert(result);
+2
source to share