问题描述
我正在尝试使用C#编写可测试某些文本或字符串的正则表达式.我希望表达式中包含< | > |< = |> = | == | != ??
Hi, I''m trying to write a regular expression in C# that can test some text or strings. I want the expression to have relational statements included < | > |<=|>= | == | != ??
Myexpression = new Regex("^[a-zA-Z_][a-zA-Z0-9_] (< | > | <=| >= | == | !=) ([a-zA-Z_][a-zA-Z0-9_] | \d*) *$");
我希望此表达式匹配任何将两个变量或一个变量与一位数字值进行比较的语句,但它不能按预期工作:(
I want this expression to match any statement that compares two variables or one variable with one digit value, but it does not work as expected:(
Help me Please!
推荐答案
我希望此表达式匹配任何将两个变量或一个变量与一位数字值进行比较的语句,但它不能按预期工作:(
请帮助我!
I want this expression to match any statement that compares two variables or one variable with one digit value, but it does not work as expected:(
Help me Please!
public static Regex regex = new Regex(
"[a-zA-Z_][a-zA-Z0-9_]\\s*(<=|>=|==|!=|<|>)\\s*[a-zA-Z_][a-zA"+
"-Z0-9_]",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
坦白地说,我感觉到您正在尝试扭曲正则表达式以更好地使用令牌和某种形式的语法检查来完成某些事情.
但是,如果您要继续,我强烈建议您获得一份 Expresso [ ^ ]-它是免费的,它确实有助于设计,解释和测试正则表达式.
To be honest, I get the feeling you are trying to twist a regex to do something that would be better done with tokens and syntax checking of some form.
However, if you are going to continue, I strongly suggest you get a copy of Expresso[^] - it''s free, and it really helps with designing, explaining and test regexes.
这篇关于用于匹配条件表达式操作语句的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!