正则表达式数大于0 [英] Regular expression number greater than 0

查看:356
本文介绍了正则表达式数大于0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要一个正则表达式来检查数字(十进制)是否大于0.这意味着以下内容应该通过
0.0001
1.0
01

以下应该失败



1a
a1
1.111a

我尝试了很多表达式但是它们都失败了。有没有人知道我可以使用的任何表达。

谢谢
Arjuna。

Hi,

I need a regular expression to check if a number(decimal) is greater than 0.  Which means the following should pass
0.0001
1.0
01

And the following should fail
1 a
1a
a1
1.111a

I tried a number of expressions but they all fail for either one of the scenarios.  Does anyone know of any expression that I can use.

Thanks
Arjuna.

推荐答案

< font face = Arial size = 2>我不相信你可以用正则表达式(#> x)实现那种业务逻辑,但是如果你能用字符,数字,大写/小写,数字来描述你的规则,阿尔法数字,那么你已经完成了。根据您的字符串应该失败,您可以使用仅接受数字的正则表达式轻松验证,并在字符串中存在任何alpha时失败。至于> 0,你需要在代码中进行检查。

你可能正在寻找类似的东西\\d +。 \d仅查找数字,句点表示您必须具有"一个或多个"数字。之前的事物(数字)。您可以使用星号(*)但该星号表示零个或多个数字,如果您想要"&";作为可接受的输入然后使用*。如果没有,如果你想拥有至少一个挖掘者,请使用加号(+)。

You could be looking for something like \d+.  The \d looks for digits only and the period says you have to have "one or more" of the things before it (digits).  You could use a star (*) but that star means zero or more digits, if you want to have "" as acceptable input then use the *.  If not, if you want to have at least one digist, use the plus (+).

正则表达式是不是一件简单的事情,如果你正在与它作斗争,那么这意味着你正在学习(并向前发展:>)。我建议使用像Expresso这样的工具来帮助您验证正则表达式和输入字符串。

Regex is not a simple thing, if you're fighting with it, then that means you're learning (and progressing forward :>).  I would suggest getting a tool like Expresso to help you with validating your regex and input strings.


这篇关于正则表达式数大于0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆