我很难找到与此模式匹配的正则表达式:
.或,),接着是-,接着是.或,),后面是H 211H 112半列或空格字符H 213>>F 214>此模式可以重复一次或多次。
以下示例应该与regex匹配:
1-2;
1-2;3-4;5-6;
1,0-2;
1.0-2;
1,0-2.0;
1-2 3-4;
1-2 3,00-4;5.0-6;以下示例不应与regex匹配:
1-2
1 2;
1_2;
1-2;3-4发布于 2011-09-30 16:22:56
编辑在1 2;移动到不匹配的基础上更新.
这应该是可行的:
@"^(\d+([,.]\d+)?-\d+([,.]\d+)?[ ;])+(?<=;)$"解释
^ //Start of the string.
( //Start of group to be repeated. You can also use (?=
\d+ //One or more digits.
([,.]\d+)? //With an optional decimal
- //Separated by a dash
\d+([,.]\d+)? //Same as before.
[ ;] //Terminated by a semi-colon or a space
)+ //One or more of these groups.
(?<=;) //The last char before the end needs to be a semi-colon
$ //End of string.发布于 2011-09-30 16:13:57
试试这个:
@"^([\d.,]+-[\d.,]+[ ;])*[\d.,]+-[\d.,]+;$"请注意,[\d.,]+接受一些通常不被视为有效的“数字”值的字符序列,例如00..,.,。您可能希望找到一个更好的正则表达式来匹配数值,并将其替换为正则表达式。
https://stackoverflow.com/questions/7613140
复制相似问题