I want to this type of demo; Simple String to here : "This is a demo text."
selection text : "demo"
Click button replace by special character => |^selectedText^|
ReplacedText : |^demo^|
removing special character when click on replace button and checking before special character added or not.
After get Original text : demo
var regexp = new RegExp(sel, "gi");
var str = blankStr;
var pattern = str.match(regexp, sel);
var replaceStr = "|^" +sel+ "^|";
document.getElementById('editable1').innerHTML = blankStr.replace(sel,replaceStr);
This seems too easy, I must still be misunderstanding. The entire thing can be replaced with: