如果我有这些字符串:
"abc" = false
"123" = true
"ab2" = false
是否有一个命令,比如IsNumeric()或其他东西,可以识别字符串是否是有效数字?
hash = window.location.hash.substr(1);
var reg = new RegExp('^[0-9]$');
console.log(reg.test(hash));
Run Code Online (Sandbox Code Playgroud)
我"123"和两者都是假的"123f".我想检查散列是否只包含数字.我错过了什么?
我有一个包含数字的字符串列表,我找不到对它们进行排序的好方法.
例如,我得到这样的东西:
something1
something12
something17
something2
something25
something29
Run Code Online (Sandbox Code Playgroud)
用这个sort()方法.
我知道我可能需要以某种方式提取数字,然后对列表进行排序,但我不知道如何以最简单的方式进行.
我希望能够编写一个函数,它以科学记数法形式接收一个数字作为字符串,并将系数和指数分开作为单独的项目.我可以使用正则表达式,但传入的数字可能不会被标准化,我更愿意能够规范化然后打破这些部分.
一位同事已经使用VB6获得了解决方案的一部分,但它并不完全存在,如下面的成绩单所示.
cliVe> a = 1e6
cliVe> ? "coeff: " & o.spt(a) & " exponent: " & o.ept(a)
coeff: 10 exponent: 5
Run Code Online (Sandbox Code Playgroud)
应该是1和6
cliVe> a = 1.1e6
cliVe> ? "coeff: " & o.spt(a) & " exponent: " & o.ept(a)
coeff: 1.1 exponent: 6
Run Code Online (Sandbox Code Playgroud)
正确
cliVe> a = 123345.6e-7
cliVe> ? "coeff: " & o.spt(a) & " exponent: " & o.ept(a)
coeff: 1.233456 exponent: -2
Run Code Online (Sandbox Code Playgroud)
正确
cliVe> a = -123345.6e-7
cliVe> ? "coeff: " & o.spt(a) & " exponent: " & …Run Code Online (Sandbox Code Playgroud) 一直在网上搜索试图解决这个问题。尝试过isnumeric,但这仅适用于AbstractChar. tryparse如果可能,我宁愿不必使用,但如果这是唯一的解决方案,那就这样吧……如果是,为什么还没有实现用于检查字符串是否为数字的函数?
我想要捕获任何大于0的数字,从0.01到999,其中.01也是可以接受的.
^([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])
Run Code Online (Sandbox Code Playgroud)
应该匹配:(如果十进制存在,最多3个数字之前和之后2个.)
.01
.1
0.01
0.1
1
10
10.1
10.11
105.1
999.99
88.00
Run Code Online (Sandbox Code Playgroud)
应该失败:
12345678.54
00564.5412
00.451
1.
,25
..25
0025
01
00,25
0
.0
0.001
999.001
e123.12
1000
Run Code Online (Sandbox Code Playgroud)
http://regex101.com/r/qZ5lC6/1 - .x并限制可选小数之前和之后的字符是麻烦的地方.