Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

如何全局替换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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

image.png

这样?

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


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

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...