2100以下数字的正则表达式 [英] Regular expression for the numbers below 2100

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

问题描述

请为我提供2100以下数字的正则表达式

Please provide me the regular expression for the numbers below 2100

推荐答案

尽管您可以为"nnnn以下的所有数字"做一个正则表达式,但是它会非常长,并且难以维护.正则表达式是文本匹配处理器,而不是数字比较器,并且有更好的方法来进行这种验证.将文本解析为整数,然后检查(如果可行)数字值.这样写起来会更快,执行起来会更快,阅读起来会更清晰,维护起来也会非常容易.


正则表达式是非常强大的工具,但是像任何其他工具一样,应将其用于正确的工作.你会用烙铁来挂画吗?
While you could do a regex for "all numbers below nnnn" it would be extremely long and difficult to maintain. Regular expressions are text matching processors, not numeric comparators, and there are better ways to do this kind of validation. Parse the text to an integer, and (if it works) check it''s numeric value. It will be quicker to write, quicker to execute, a lot clearer to read, and much, much easier to maintain.


Regexes are very powerful tools, but like any tool, they should be used for the correct job. Would you use a soldering iron to hang a picture?


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

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