使用javascript中的正则表达式从文本中过滤掉数字 [英] Filter out numbers out of a text using regular expressions in javascript
本文介绍了使用javascript中的正则表达式从文本中过滤掉数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 javascript 正则表达式从文本中获取数字的最佳方法是什么?例如......我有$ 4,320 text/followme",我想从中获得4320.但是,我想避免在第一次出现字母表或除逗号 ',' 以外的任何非字母表之后使用数字
What will be the best way using javascript regular expression to get numbers out of text.. e.g.... I have "$4,320 text/followme" and I want to get 4320 out of this. However I want to avoid numbers after first occourance of an alphabet or any non alphabet other than a comma ','
这样,如果我有 4,320 美元 t234ext/followme,它仍然会返回给我 4320.输入总是以 $ 开头
so that if i have $4,320 t234ext/followme it will still return me 4320. The input will always have $ sign at the beginning
所以正则表达式应该返回
so the regular expression should return
$4,320 text/followme returns 4320
$4,320 t3444ext/followme return 4320
$4,320 /followme return 4320
$4320 text/followme return 4320
$4320 t3444ext/followme return 4320
$4320 /follow4me return 4320
推荐答案
string.split(/ /)[0].replace(/[^\d]/g, '')
这篇关于使用javascript中的正则表达式从文本中过滤掉数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文