如何全局替换width的单位(px)换成(upx)

正则将width: (任意数字)px变成 width:(任意数字)upx

`let data='<p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; box-sizing: border-box;"> </p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; box-sizing: border-box;">严格来讲你做的没有错,策略不可能是个秘密,基于现在互联网的特点,即使你今天不讲,你也得给投资人讲。所以你要将你的策略公开,你要给投资人讲,你要给员工讲,你不能说我公司的策略是保密的,这基本上是不可能的事情,需要保密的事情是具体的执行。</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; box-sizing: border-box;"> </p></section></section></section><p><br/></p><section style="text-align: justify; white-space: normal; position: static; box-sizing: border-box;"><section style="margin-top: 10px; margin-bottom: 10px; position: static; box-sizing: border-box;"><section style="display: inline-block; width: 663.111px; border: 2px dashed rgb(192, 200, 209); padding: 10px; background-color: rgb(239, 239, 239); box-sizing: border-box;"><section style="box-sizing: border-box;"><section style="position: static; box-sizing: border-box;">'

data.replace(/width:([s+]?d+)px/g,'width: ${1}upx')
`
想把中间的width:px换成width:upx

阅读 2.6k
1 个回答

image.png

这样?

width:([\s+]?[+-]?(0|([1-9]\d*))(\.\d+)?)px 替换为 width: $1upx


针对问题补充的运行结果:

image.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题