能否请你帮我写的正则表达式这个帮助。正则表达式 - 请在形成这个表达式
NAME = “Windows产品为.NET”
TYPE = “软件编程”
数量= “3包”
我希望做一个匹配这样的在我需要RegEx的c#中。
If Name.contains(".Net") && (Type.Contains("Programming") || Type.Contains("Hardware")
{
// output will be a Match.
}
else
{
// no match.
}
我想在这里拿,指定每个条件的正则表达式,然后应用逻辑操作数& &,逻辑分组paranthesis然后逻辑运算||这种方法。 我想出了这些所有的正则表达式。我怎样才能提供逻辑操作数为他们每个人以适当的顺序执行?
string Name = "Windows Product for .Net";
string Type = "Software Programming";
string patternForName = ".*Net";
Regex rgxName = new Regex(patternForName);
Match matchName = rgx.Match(Name);
string patternForType = ".*Programming";
Regex rgxType = new Regex(patternForType);
Match matchType = rgx.Match(Type);
string patternForType1 = ".*Hardware";
Regex rgxType1 = new Regex(patternForType1);
Match matchType1 = rgx.Match(Type);
请注意 - 我们正在创造一种动态的,模式,操作数和正则表达式从XML文件来的感觉。所以这就是为什么我不想为上面写一个大的regEx。
我不确定我是否遗漏了某些东西,但是从您的示例中可以看出,如果所有使用的都是.Contains,则不需要RegEx。你有更复杂的模式,你需要匹配? – mservidio 2011-06-15 16:23:10