正则表达式问题的复杂性,例如MS Word打印 [英] Regular Expression Question Complexity like MS Word Printing

查看:103
本文介绍了正则表达式问题的复杂性,例如MS Word打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表示问题复杂性的文本框,并且
有效案例:
案例#01:1,2,5,7,9
案例#02:3-5
案例#03:1、2、5-7

在有效案例01(粗体)中:1,4, 5-7-8
在有效情况02中: 2-4-6-8 ,正确的方法是2-8

这里的数字是问题的复杂度.该算法将根据选择的问题复杂度生成问题.

例如,在案例#02中(将选择所有复杂度为3,4和5的问题)

对于案例#03(将选择复杂度为1,2和5,6,7的所有问题)

经过大量测试后,我的Tested正则表达式是

I have text box for Question Complexity,and
Valid Cases :
Case #01 : 1,2,5,7,9
Case #02 : 3-5
Case #03 : 1,2,5-7

In Valid Case 01 (bold): 1,4,5-7-8
In Valid Case 02 : 2-4-6-8, Correct way is 2-8

Here numbers are complexities of question.The algorithm will generate question according to selected question complexity.

For example in Case #02 ( all questions with complexity of 3,4 and 5 will be selected)
and
For Case #03 ( all question with complexity 1,2 and 5,6,7 will be selected)

my Tested regular expression after lots of testing is

\d+(,\d|(-\d+)(,\d+))* 



但是有问题
它正在解决问题并进行处理(例如2-5-7),但最后也需要(,digit).


要在线测试正则表达式,您可以访问:正则表达式在线测试

请有人可以帮助我.我需要验证诸如Microsoft Word打印选项之类的复杂性.
否则任何链接或参考都将有所帮助.谢谢



but there is a problem
it is solving the problem and handling ( ex 2-5-7 ) but it requires (,digit) in the end aswell.


for testing regular expression online you can visit : regular expression online testing

Please can some one help me in this. i need to validate complexity like Microsoft Word Printing options.
Or any link or reference will be helpful. Thanks

推荐答案

^(\d+|\d+-\d+)(,(\d+|\d+-\d+))*
^(\d+|\d+-\d+)(,(\d+|\d+-\d+))*



似乎可以工作.但是请记住,这还会允许您不希望使用"100-3"之类的范围,因此您可能需要在代码中进行一些额外的错误检查.

Seems to work. But remember, this would also allow for a range like "100-3", which you may not want, so you might need some extra error checking in your code.


如何命名捕获组:
How about a named capture group:
(?<many>\d+(\-\d+)+)|(?<one>(?<=^|,)\d+(?=


这篇关于正则表达式问题的复杂性,例如MS Word打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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