替换ckeditor中的内容标记html

时间:2012-11-14 04:30:32

标签: javascript regex ckeditor

我通过命令

获取ckeditor中的内容

var content = $('#editor1').val(); // With editor1 is my ckeditor

我收到一个像<h3 class="Interview">any word(may be unicode)</h3>这样的字符串 如何通过javascript ????

将其替换为<h3 class="Interview">My word</h3>

请帮帮我!!!谢谢!!!

3 个答案:

答案 0 :(得分:0)

这应该有效

result = subject.replace(/(<[a-z][a-z0-9]*[^<>]*>)([a-z][a-z0-9]*[^<>]*)(<\/?[a-z][a-z0-9]*[^<>]*>)/, "$1 My words $3");

答案 1 :(得分:0)

您可以使用regexp:

来实现
var a = '<h3 class="Interview">any word(may be unicode)</h3>'
a = a.replace(/(<h3[^>]*>)[^<]*<\/h3>/g, '$1'+'your words</h3>')

答案 2 :(得分:0)

试试这个:

var str="<h3 class=\"Interview\">any word(may be unicode)</h3>";

function htmlTextReplace(original){
    var regex = />([^<]*)</g;
    return original.replace(regex, function($0, $1){
      return $0.replace($1, strTextReplace($1, 'any word','your words'));
    });
 }

function strTextReplace(str, ow, dw){
    return str.replace(ow, dw);
}
console.log(htmlTextReplace(str));