如何代表正则表达式编号范围(例如1到12)? [英] How to represent regex number ranges (e.g. 1 to 12)?
本文介绍了如何代表正则表达式编号范围(例如1到12)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在使用([1-9] | 1 [0-2])
表示从1到12的输入。(不允许前导零。)
I'm currently using ([1-9]|1[0-2])
to represent inputs from 1 to 12. (Leading zeros not allowed.)
但是似乎有些 hacky ,在某些情况下,它看起来完全脏。
However it seems rather hacky, and on some days it looks outright dirty.
☞有内置的适当方法吗?
☞还有什么其他方法代表数字范围?
☞ What are some other ways to represent number ranges?
推荐答案
我倾向于使用 [2-9] | 1之类的形式[0-2]?
可以避免回溯,尽管在这里没什么区别。尽管regex可以很好地处理XML Schema,但我已经避免了这种歧义。
I tend to go with forms like [2-9]|1[0-2]?
which avoids backtracking, though it makes little difference here. I've been conditioned by XML Schema to avoid such "ambiguities", even though regex can handle them fine.
这篇关于如何代表正则表达式编号范围(例如1到12)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文