也許這是因爲我完全炸的權利,但是這個代碼:C#.NET正則表達式工作不正常
static void Main(string[] args)
{
Regex regx = new Regex(@"^.*(vdi([0-9]+\.[0-9]+)\.exe).*$");
MatchCollection results = regx.Matches("vdi1.0.exe");
Console.WriteLine(results.Count);
if (results.Count > 0)
{
foreach (Match r in results)
{
Console.WriteLine(r.ToString());
}
}
}
應該產生輸出:
2
vdi1.0.exe
1.0
如果我不瘋狂。相反,它只是生產:
1
vdi1.0.exe
我錯過了什麼?
我想你必須使用'Groups'屬性來訪問子組。 –
邁克是對的。你混淆與團體的比賽。 – Sven
作爲一個觀點,Regex有沒有組1.1「? 'vdi1.0.exe'中不會發生這種情況。你是不是指'1.0'? – voithos