正则匹配开头结尾

正则匹配以/upload开头,以.jpg结尾的字符串,并在字符串开头加上域名'http://www.baidu.com'


    var regExp = /\/upload.*?\jpg/g

    var str = '<p><img src="/upload/ueditor/image/20180731/1533004283191841.jpg"/><img src="/upload/ueditor/image/20180731/1533004286143417.jpg"/><img src="/upload/ueditor/image/20180731/1533004293153816.jpg"/></p><p class="attr-list-hd tm-clear" style="margin-top: 0px; margin-bottom: 0px; padding: 5px 20px; line-height: 22px; color: rgb(153, 153, 153); font-family: tahoma, arial, 微软雅黑, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="margin: 0px; padding: 0px; font-weight: 700; float: left;">产品参数:</span></p><ul id="J_AttrUL" style="list-style-type: none;" class=" list-paddingleft-2"><li><p>产品名称:Nike/耐克 315123</p></li><li><p>是否商场同款:&nbsp;是</p></li><li><p>颜色分类:&nbsp;白色/白色&nbsp;黑色/黑色</p></li><li><p>款号:&nbsp;315123</p></li><li><p>品牌:&nbsp;Nike/耐克</p></li><li><p>上市时间:&nbsp;2016年秋季</p></li><li><p>吊牌价:&nbsp;799</p></li><li><p>性别:&nbsp;男子</p></li><li><p>鞋帮高度:&nbsp;中帮</p></li><li><p>帮面材质:&nbsp;其他</p></li><li><p>鞋底材质:&nbsp;其他</p></li><li><p>功能:&nbsp;包裹性</p></li><li><p>鞋码:&nbsp;38.5&nbsp;39&nbsp;40&nbsp;40.5&nbsp;41&nbsp;42&nbsp;42.5&nbsp;43&nbsp;44&nbsp;44.5&nbsp;45&nbsp;45.5&nbsp;46&nbsp;47.5</p></li><li><p>运动系列:&nbsp;运动时尚鞋</p></li><li><p>闭合方式:&nbsp;系带</p></li><li><p>流行元素:&nbsp;车缝线</p></li><li><p>是否瑕疵:&nbsp;否</p></li></ul><p><img src="/upload/ueditor/image/20180731/1533004268383885.jpg"/><img src="/upload/ueditor/image/20180731/1533004273911464.jpg"/></p>'

    str = str.replace(regExp ,'http://www.baidu.com'+regExp.exec(str)[0])
 

 

你可能感兴趣的:(前端)