是否有一个简单的正则表达式来将数字与 x 进行比较? [英] Is there a simple regex to compare numbers to x?

查看:25
本文介绍了是否有一个简单的正则表达式来将数字与 x 进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果数字大于或等于任意数字,我想要一个正则表达式.对于这样一个简单的任务来说,这似乎非常复杂……似乎您需要在为 x 手工制作的显式正则表达式中重新发明计数".

I want a regex that will match if a number is greater than or equal to an arbitrary number. This seems monstrously complex for such a simple task... it seems like you need to reinvent 'counting' in an explicit regex hand-crafted for the x.

例如,直观地对大于 25 的数字执行此操作,我得到

For example, intuitively to do this for numbers greater than 25, I get

(\d{3,}|[3-9]\d|2[6-9]\d)

如果号码是 512345 呢?有没有更简单的方法?

What if the number was 512345? Is there a simpler way?

推荐答案

似乎没有更简单的方法.正则表达式不是数字的东西.
你可以试试这个:

Seems that there is no simpler way. regex is not thing that for numbers.
You may try this one:

\[1-9]d{6,}|
[6-9]\d{5}|
5[2-9]\d{4}|
51[3-9]\d{3}|
512[4-9]\d{2}|
5123[5-9]\d|
51234[6-9]

(为了清晰起见,换行)

(newlines for clarity)

这篇关于是否有一个简单的正则表达式来将数字与 x 进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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