Generate an abbreviation form a string in JavaScript using regular expressions?

Abbreviation of a string in JavaScript using a Regular Expressions

Table of Contents
  1. HTML View for Description textarea
  2. JavaScript methods and call onkeyup 

For example, when we type ccc and press the space key that time [ccc => conference call with customer]. here the value of ccc is predefined the array list. 

<textarea id="txtDescription" onkeyup="return checkAbbreviationKey(event)"></textarea>

JavaScript methods and call onkeyup 

function checkAbbreviationKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode == 32) {          
            var charStr =\S+/g)
            var abbreviations = isAbbreviations();               
            if (abbreviations.length > 0) {
               for(var index in abbreviations) {
                   var reg = new RegExp("\\b" + abbreviations[index].Anchor + "\\b", "g");
                   if (charStr[charStr.length - 1].match(reg)) {
                       charStr[charStr.length - 1] = abbreviations[index].ExpandedText;
              = charStr.join(" ");

function isAbbreviations() {
    var abbreviationsList = ConstraintsList();        
    return abbreviationsList;


Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2 Powered by Blogger.