I want to format user input on client side only and replace <br/> that returned from server to <br/> html element.
I have the below javascript code to format user input
function HtmlEncode(s){
  var el = document.createElement("div");
  el.innerText = el.textContent = s;
  s = el.innerHTML;
  return replace_chat_tags(s);
}
I use the below function to replace url and email from client
function replace_chat_tags(chat_body = '') {
  return chat_body
    .replace( /((http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?=\-&_/]+)/g, "<a href=\"$1\" target=\"_blank\">$1</a>" )
    .replace( /\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b/gi, "<a href=\"mailto:$1\">$1</a>" )
    .replace( /<br\/>/g, "<br/>" );
}
My problem is the above code doesn't replace < and > when it match it still return <br\/>, Can somebody give me a hint on this?
HtmlEncode(chat.message)
")`? Without a regex. – Nandu Kalidindi Oct 26 '17 at 14:20