能否請你幫我寫的正則表達式這個幫助。正則表達式 - 請在形成這個表達式
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