如何使用JavaScript从数字+度量单位字符串中提取数字? [英] How might I extract the number from a number + unit of measure string using JavaScript?
本文介绍了如何使用JavaScript从数字+度量单位字符串中提取数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这个字符串
str = "22px";
如何仅提取数字22?谢谢。
How do I extract just the number 22? Thanks.
推荐答案
你可以试试str.match(/ \d + /);
You could try str.match(/\d+/);
这篇关于如何使用JavaScript从数字+度量单位字符串中提取数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文