开发者

How do I write 0-999 using regex?

I have this regex, see below:

/(ANY|1-9|[A-Za-z0-9])/g

Is the a way of adding 0-999 in the re开发者_如何学编程gex I have already?

Thanks


^(0|[1-9]\d{,2})$

If 001 etc. are not allowed (must either be 0 or begin with 1-9)


If to be combined with /(ANY|1-9|[A-Za-z0-9])/g, you can:

/(ANY|1-9|[A-Za-z0-9]|[1-9]\d{1,2})/g

(The 0-9 range is already matched in the [A-Za-z0-9] part.)


EDIT
It appears that the shorthand \d{,2} is not PCRE compliant. Replace with \d{0,2} if using the first (isolated) solution.


/^(ANY|1-9|[A-Za-z0-9]|\d{1,3})$/g

what exactly do you want to match with ANY and 1-9 ?


/\d?\d?\d/

1234567890123456790-


In order not to have leading zeros:

((?:^\d$)|(?:^[1-9]\d$)|(?:^[1-9]\d\d$))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜