从数字范围生成正则表达式
我想从数字范围生成一个(系列)正则表达式。
示例:
1013 - 4044 =>
regexp matches
---------------------------------------
101[3-9] 1013 - 1019
10[2-9][0-9] 1020 - 1099
11[0-9][0-9] 1100 - 1199
[23][0-9][0-9][0-9] 2000 - 3999
40[0-3][0-9] 4000 - 4039
404[0-4] 4040 - 4044
最简单的算法是什么?
扭转它的最简单方法是什么(即给定正则表达式,寻找范围)?
很高兴看到 java、clojure、perl 中的解决方案...
谢谢!
I'd like to generate a (series of) regexp(s) from a numeric range.
Example:
1013 - 4044 =>
regexp matches
---------------------------------------
101[3-9] 1013 - 1019
10[2-9][0-9] 1020 - 1099
11[0-9][0-9] 1100 - 1199
[23][0-9][0-9][0-9] 2000 - 3999
40[0-3][0-9] 4000 - 4039
404[0-4] 4040 - 4044
what is the simplest algorithm?
What is the easiest way to reverse it (i.e. given the regexps, looking for the ranges)?
Would be nice to see solutions in java, clojure, perl...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个在线工具用于在给定范围内生成正则表达式,并提供解释。您也可以在那里找到源代码。例如:
要反转它,您可以查看字符类,并获取每个替代项的最小值和最大值。
There is an online tool for generating regex given a range, and provides the explanation. You can find the source code there also. For example:
To reverse it, you can look at the character classes, and get the minimum and maximum for each alternative.