小程序中直接使用正则会报错,需要用它自身提供的方法:

https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/06datatype.html

微信小程序使用正则表达式替换HTML标签

代码:

其中  f  即传入的富文本内容,font为替换之后的内容

    let reg = getRegExp("<[^>]+>", "g");
    let font = f.replace(reg,' ')

相当于:

let font = f.replace(/<[^>]+>/g,'');

但是如果直接在小程序中这样写,会报错:

微信小程序使用正则表达式替换HTML标签

前后效果展示:

微信小程序使用正则表达式替换HTML标签 =>微信小程序使用正则表达式替换HTML标签

相关文章:

  • 2021-05-06
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-06-12
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-02-06
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案