Welcome to Qi-U Community for programmer and developer-Open, Learning and Share

Categories

0 votes
149 views
in Technique[技术] by (31.9m points)

js,求一条正则该怎么写

'160px'.replace(/xxx/,'') => '160'
'160.66px'.replace(/xxx/,'') => '160'

求解一条正则上面两种情况都能满足


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

Please log in or register to answer this question.

1 Answer

0 votes
by (31.9m points)
// => 160
'160px'.replace(/(^d+)(.*)/, '$1')

// => 160
'160.66pxpx'.replace(/(^d+)(.*)/, '$1')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Qi-U Community for programmer and developer-Open, Learning and Share
...