RegEx:如何匹配所有大于 954 的数字? [英] RegEx: How can I match all numbers greater than 954?
本文介绍了RegEx:如何匹配所有大于 954 的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过 ^([0-9]\d|\d{4,})$
但它没有给出正确的结果.
I tried ^([0-9]\d|\d{4,})$
but it does not give the correct result.
推荐答案
我不会为此使用正则表达式,因为您会陷入丑陋的模式链中.
I would not use a regex for this since you will fall in an ugly chains of patterns.
但是,如果仍然必须或想要使用一个,您可以使用这样的正则表达式:
However, if still have to or want to use one, you can use a regex like this:
[1-9]\d{3,}|9[6-9]\d|9[5-9]{2}
这个正则表达式背后的想法是:
The idea behind this regex is:
[1-9]\d{3,} --> This will match 4 or more digit numbers
9[6-9]\d --> This will match numbers between 960 to 999
9[5-9]{2} --> This will match numbers between 955 to 999
you could write this pattern as `95[5-9]` to cover
numbers from 955 to 959 if you wish (it's up to you)
这篇关于RegEx:如何匹配所有大于 954 的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文