您当前的位置: 首页 >  小程序

培根芝士

暂无认证

  • 0浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

小程序正则替换

培根芝士 发布时间:2021-07-02 11:29:24 ,浏览量:0

  • 使用正则替换字符串

原始数据:

2020-8-3 18:18:23

str.replace(new RegExp('-','g'),'.');

或

str.replace(/-/g,'.');

替换结果:

2020.8.3 18:18:23

  • 使用正则替换HTML中的图片 

原始数据:

 

hello world

let reg = new RegExp("]*src=['\"]([^'\"]+)[^>]*>", "g");
html = html.replace(reg, function (match, capture) {
    console.log(match)
    console.log(capture)
    return ''
});

或者 

html = html.replace(/]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture){
    console.log(match)
    console.log(capture)
    return ''
});

替换结果:

 

hello world

 

 

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.0561s