java中正和负十进制值的正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2072222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Regular expression for positive and a negative decimal value in java
提问by Abhi
Regular expression for negative and positive decimal value so that can be matched with string using pattern and matcher for the correct implementation can any one will provide me with that
负和正十进制值的正则表达式,以便可以使用模式和匹配器与字符串匹配以进行正确的实现,任何人都可以为我提供
采纳答案by FreddyB
(\+|-)?([0-9]+(\.[0-9]+))
回答by Rubens Farias
Try this:
尝试这个:
[+-]?\d+\.\d+
回答by RonY
Try This! I've also used this way
尝试这个!我也用过这种方式
"^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$"
Rules:
规则:
ex: ^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$
^ # Start of string
[0-9]{1,12} # Match 1-12 digits (i. e. 0-999999999999)
(?: # Try to match...
\. # a decimal point
[0-9]{1,4} # followed by one to three digits (i. e. 0-9999)
)? # ...optionally
$ # End of string
回答by Abdurrahman Mubeen Ali
+ (BOOL)isStringADecimalNumber:(NSString *)string
{
NSString *regex = @"([+]|-)?(([0-9]+[.]?[0-9]*)|([0-9]*[.]?[0-9]+))";
NSPredicate *test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL stringIsADecimalNumber = [test evaluateWithObject:string];
return stringIsADecimalNumber;
}
Highlighted below, are the numbers that return TRUE
for this regex:
下面突出显示的是TRUE
此正则表达式返回的数字: