|^s..." /> |^s..." /> |^s..."/>

Why not selection text replaced by special character and how to remove this special character?

97 views Asked by At

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

jsfiddle 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);
1

There are 1 answers

1
Barmar On

This seems too easy, I must still be misunderstanding. The entire thing can be replaced with:

document.getElementById('editable1') = '|^' + sel + '^|';