以下是可以替换所有HTML标记的正则表达式:

/<[^>]+>/g

这个正则表达式会匹配所有的HTML标记,包括标签名和属性,如<a href="http://example.com">link</a>会被替换为link。如果需要保留一些标记,可以使用replace方法的回调函数。例如,以下代码会保留<a>标签和&nbsp;

const html = '<a href="http://example.com">link</a>&nbsp;';
const result = html.replace(/<[^>]+>/g, (match) => {
  if (match === '<a>' || match === '&nbsp;') {
    return match;
  } else {
    return '';
  }
});
console.log(result); // <a>link</a>&nbsp;
a  img src=imageswindfilenewgif align=absmiddle title=新帖标志 tdtd class=tal y-stylea href=uphpaction=show&uid=1014482 class=bl無印優品a可以替换所有HTML标记的正则如a、  img

原文地址: https://www.cveoy.top/t/topic/C54 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录