Reputation: 437
I can change a word in ckeditor with this regex,
editor = CKEDITOR.instances.txtisi;
var edata = editor.getData();
var rep_text = edata.replace("INSERT INTO", "INSERT-INTO");
editor.setData(rep_text);
but how to add more words that will replace, not only one word. i have try but i get the last word always. like this.editor = CKEDITOR.instances.txtisi;
var edata = editor.getData();
var rep_text = edata.replace("INSERT INTO", "INSERT-INTO"); // you could also
var rep_text = edata.replace("DELETE TABLE", "DELETE-TABLE"); // you could also
var rep_text = edata.replace("TRUNCATE TABLE", "TRUNCATE-TABLE"); // you could also use a regex in the replace
editor.setData(rep_text);
Upvotes: 0
Views: 440
Reputation: 4166
There is a bug in your code
This is the fixed version
var edata = editor.getData();
var edata = edata.replace("INSERT INTO", "INSERT-INTO"); // you could also
var edata = edata.replace("DELETE TABLE", "DELETE-TABLE"); // you could also
var edata = edata.replace("TRUNCATE TABLE", "TRUNCATE-TABLE"); // you could also use a regex in the replace
editor.setData(edata);
The reason is that string.replace() returns a NEW string and leaves the old one unaffected. (Just like any string operations btw). So you need to update edata
variable with fresh data after each call to .replace()
Upvotes: 1