if(data.message.indexOf("#") != -1){ var newDm = ""; var msgHash = data.message.split(" "); for(var i = 0; i < msgHash.length; i++){ if(msgHash[i].indexOf("#") == 0 && msgHash[i].length > 2 && msgHash[i].substr(1, msgHash[i].length-2).replace(/\W/g, '') == msgHash[i].substr(1, msgHash[i].length-2)){ newDm += "" + msgHash[i] + " "; } else { newDm += msgHash[i] + " "; } } data.message = newDm; }