2013-10-18 33 views
0

,它工作正常,但Regex.Matches返回我只 1的比賽,該初始字符串。C#正則表達式不返回匹配

這裏是正則表達式

(\d+)(?:\s*)(?:([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4}))(?:\s*)(?:\w*)(?:\s*)(.*) 

這裏是樣本串,我嘗試解析

50 0000.74b9.ed90 DYNAMIC  Gi0/20 
+1

什麼了比賽?什麼應該匹配? – Max

+0

沒有努力的感覺。 – jersoft

+0

我希望有5場比賽:50,0000,74b9,ed90,Gi0/20 –

回答

2

嘗試使用匹配,而不是比賽。 索引[0]是整個比賽。

Regex.Match("50 0000.74b9.ed90 DYNAMIC  Gi0/20", @"(\d+)(?:\s*)(?:([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4}))(?:\s*)(?:\w*)(?:\s*)(.*)").Groups[1].ToString() 

Regex.Match(input,regex).Groups[1].ToString() 
Regex.Match(input,regex).Groups[2].ToString() 
Regex.Match(input,regex).Groups[3].ToString() 
.... 
+0

隨着Regex.Matches我得到初始字符串作爲比賽,我希望有5場比賽,就像它在JavaScript或preg_match_all在PHP –

+0

您將獲得五場比賽在Groups集合。 – jersoft

+0

謝謝!這工作! –

相關問題