使用RegEx筛选可变长度的数字序列吗? [英] Use RegEx to filter for a variable length numeric series?
问题描述
我只知道如何使用RegEx这样的\ d {4}来过滤固定长度的数字序列.但这不是我想要的,因为要检查的序列可以有不同的长度.
您能给我尽可能多的解决方案吗?
非常感谢您!
I know only the how to filter for a fixed length numeric series using RegEx like this \d{4} . But that''s not I want because the series to be checked can have a various length.
Could you please give me as many solutions as possible?
Thank you very much!
推荐答案
Medhi是正确的-
Medhi is right -
\d*
可以工作-但是,我建议
will work - however, I would suggest
\d+
,而不是因为它至少需要一位数字才能匹配(\ d *将匹配"A12",因为这三个匹配项:NULL,"12",NULL-\ d +将匹配只找到"12").
如果要使用Regexes,请获取 Expresso [
instead as it requires a minimum of one digit in order to match (\d* will match "A12" as three matches: NULL, "12", NULL - \d+ will only find the "12").
If you are going to use Regexes, then get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.
使用以下命令获取尽可能多的数字:
Use the following for getting as many digits as there are :
\d*
我建议 \ d + (至少一位)
但是,如果您想获取科学数字,请执行以下操作:
[-+]?[0-9] * \.?[0-9] +([eE] [-+]?[0-9] +)?
在这里测试:
http://www.regular-expressions.info/javascriptexample.html [
I suggest \d+ (at least one digit)
but if you want to capture scientific numbers :
[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?
test it here :
http://www.regular-expressions.info/javascriptexample.html[^]
这篇关于使用RegEx筛选可变长度的数字序列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!