JavaScript RegExp match text ignoring HTML

后端 未结 6 1965
时光取名叫无心
时光取名叫无心 2020-12-09 22:28

Is it possible to match \"the dog is really really fat\" in \"The dog is really really fat!\" and add \"

6条回答
  •  醉话见心
    2020-12-09 23:07

    Naah... just use the good old RegExp ;)

    var htmlString = "The dog is really really fat!";
    var regexp = /<\/?\w+((\s+\w+(\s*=\s*(?:\".*?"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/gi;
    var result = '' + htmlString.replace(regexp, '') + '';
    

提交回复
热议问题