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

版权声明: https://blog.csdn.net/qq_23521659/article/details/86007879

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

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

代码:

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

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

相当于:

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

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

前后效果展示:

 =>

猜你喜欢

转载自blog.csdn.net/qq_23521659/article/details/86007879