110,533
社区成员
发帖
与我相关
我的任务
分享
------------------
0 Device: Texas Instruments XDS100v3 A, ID:XDS-06Z4LS8QA,
Chip: CC2640
1 Device: Texas Instruments XDS100v3 A, ID:XDS-06Z4LS8QA,
Chip: CC2640
2 Device: USB Serial Port (COM19), ID:COM19,
Chip: Unknown
3 Device: 通信端口 (COM1), ID:COM1,
Chip: Unknown
-------------------------------------------------------------------------------
Regex reg = new Regex(@"(\d+)\s+Device:\s([^,]*),\sID:([^,]*),\s+Chip:\s([^\s]*)");
Match m = reg.Match(msg);
while (m.Success)
{
Console.WriteLine("第{0}个\n\t设备:\t{1}\n\tID:\t{2}\n\t芯片:\t{3}\n\n", m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value, m.Groups[4].Value);
m = m.NextMatch();
}
把所有信息都取出来了,想怎么处理自已看着办就行string regExp = @"\d\sDevice(.|\n)+?CC2640";
string msg = @"0 Device: Texas Instruments XDS100v3 A, ID:XDS-06Z4LS8QA,
Chip: CC2640
1 Device: Texas Instruments XDS100v3 A, ID:XDS-06Z4LS8QA,
Chip: CC2640
2 Device: USB Serial Port (COM19), ID:COM19,
Chip: Unknown
3 Device: 通信端口 (COM1), ID:COM1,
Chip: Unknown";
List<string> numbers = new List<string>();
MatchCollection colloction = Regex.Matches(msg.Trim(), regExp);
if (colloction.Count > 0)
{
Console.WriteLine("匹配{0}条。",colloction.Count);
for (int i = 0; i < colloction.Count; i++)
{
numbers.Add(colloction[i].Value.Substring(0,1));
//Console.WriteLine(colloction[i].Value);
}
}
这个应该就是你想要的吧。
foreach(var m in Regex.Matches(strText,@"(\d+\s+Device).*?Chip:\s*(\w+)")){
Console.WriteLine(m.Groups[1].Value + "\t" + m.Groups[2].Value);
}