一、匹配img替换或清空(width、height)
1、替换 img 中的width / height
res
.content
= res
.content
.replace(/<img
[^>]*>/ig
, function(match
, capture
) {
match
= match
.replace(/(width
="(.*?)")|(height
="(.*?)")/ig
,
function(getFirst
, getSecond
) {
let numArr
= getFirst
.split('=');
let num
= numArr
[0] + '=' + Number(JSON
.parse(numArr
[1])) / 1.6 ;
return num
});
return match
})
2、将img中width / height清空
match
= match
.replace(/(style
="(.*?)")|(width
="(.*?)")|(height
="(.*?)")/ig
, '');
二、匹配后台html模板中的font-size,将px --> rpx
res
.content
= res
.content
.replace(/font
-size
:\w
+;?/g
, function(val
, group
) {
val
= val
.replace(/(\d
+)px
/g
, function(value
, groupp
) {
return groupp
+ 'rpx'
})
return val
})
转载请注明原文地址: https://lol.8miu.com/read-28347.html