string input="a=1 and b>=2 and c<3 and d between 1 and 3"; Regex reg=new Regex(@"[a-zA-Z]+?[\s=><]+?\d(\sand\s\d)?");string str1=reg.Match(input); string str2=reg.Match(input).NextMatch(); string str3=reg.Match(input).NextMatch().NextMatch(); string str4=reg.Match(input).NextMatch().NextMatch().NextMatch(); 写个循环也可以把这些数取出来。。这样比较明了。。
这个用正则不容易实现,楼上的回答考虑的情况有点片面。 条件是可以用and连接,也可以用or连接,如:a < 2 or a >3 每一个条件中所使用的运算符多种多样,如: comparison operators: > -- greater than < -- less than >= -- greater than or equal to <= -- less than or equal to <> -- not equal to BETWEEN Operator: value-1 [NOT] BETWEEN value-2 AND value-3 value-1 >= value-2 AND value-1 <= value-3 NOT (value-1 >= value-2 AND value-1 <= value-3)IN Operator: value-1 [NOT] IN ( value-2 [, value-3] ... )LIKE Operator: value-1 [NOT] LIKE value-2 [ESCAPE value-3]IS NULL Operator: value-1 IS [NOT] NULL...........当然,条件中如果在包含子查询, 那就更不好解决了。 当然这个问题不是不可以解决,只是解决起来比较麻烦,也不是正则就可以解决的。
Regex reg=new Regex(@"[a-zA-Z]+?[\s=><]+?\d(\sand\s\d)?");string str1=reg.Match(input);
string str2=reg.Match(input).NextMatch();
string str3=reg.Match(input).NextMatch().NextMatch();
string str4=reg.Match(input).NextMatch().NextMatch().NextMatch();
写个循环也可以把这些数取出来。。这样比较明了。。
条件是可以用and连接,也可以用or连接,如:a < 2 or a >3
每一个条件中所使用的运算符多种多样,如:
comparison operators:
> -- greater than
< -- less than
>= -- greater than or equal to
<= -- less than or equal to
<> -- not equal to BETWEEN Operator:
value-1 [NOT] BETWEEN value-2 AND value-3
value-1 >= value-2 AND value-1 <= value-3
NOT (value-1 >= value-2 AND value-1 <= value-3)IN Operator:
value-1 [NOT] IN ( value-2 [, value-3] ... )LIKE Operator:
value-1 [NOT] LIKE value-2 [ESCAPE value-3]IS NULL Operator:
value-1 IS [NOT] NULL...........当然,条件中如果在包含子查询, 那就更不好解决了。
当然这个问题不是不可以解决,只是解决起来比较麻烦,也不是正则就可以解决的。