接受浮点数和减号 (-) 的正则表达式 [英] Regex that accepts floating point numbers and minus (-) sign
本文介绍了接受浮点数和减号 (-) 的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个只接受 0 到 9 之间的浮点数和减号的正则表达式.
I want a regular expression that will accept only floating point numbers from 0 to 9 and minus sign.
请帮忙.
推荐答案
^[-+]?[0-9]*\.?[0-9]+$
^
- 字符串的开始[-+]?
- 0 或 1 符号指示符[0-9]*
- 0 个或多个整数\.
- 字符.
(.
在正则表达式中用于表示任何字符")[0-9]+
- 1 个或多个整数$
- 字符串的结尾
^
- start of string[-+]?
- 0 or 1 sign indicator[0-9]*
- 0 or more integers\.
- the character.
(.
is used in regex to mean "any character")[0-9]+
- 1 or more integers$
- the end of the string
如果您使用逗号作为十进制分隔符,请使用 ,
而不是 \.
If you are instead using the comma as a decimal seperator, use ,
instead of \.
如果你同时使用两者,你可以使用 [.,]
If you are using both/either, you can use [.,]
这篇关于接受浮点数和减号 (-) 的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文