-
需求:
匹配
{
[(),(),(),(),(),()],
[(),(),(),(),(),()],
[(),(),(),(),(),()]
}
匹配其中的()中的数据。并且记录其序号。第一()
数据的序号就是1。 -
思路,可以先匹配一行,然后再匹配()中的数据
-
主要代码
string dataStr = "{[(04FFFC800084E27F1FE1CBD894FE1E82),(04FFFA7000CF63F439FB921FD42F9EC6),(04FFF6900098B08F05865248CF289EC5)," +
"(04FFFB50002739329E1FCDA3229727B1),(04FFFC2000DB83BC36B2617BFC1B9EC3),(04FFF9700073B0BF0E9AC86BFF0327B0),(04FFF28000D3B0BF0E9AC86BFF0327B0),(04FFF98000E8ED6E963E7342EA9409EC)]," +
"(04FFFDA000851A7F1FE1CBD894FE1E82),(04FFFA7000D7E37C30720B175CB79EB8)],[(04FFF950000598ED6E963E7342EA7A09),(04FFFCA00085267F1FE1CBD894FE1E82),(04FFF84000852A7F1FE1CBD894FE1E82)," +
"(04FFFB1000DB83BC36B2617BFC1B9EB4),(04FFF0C00085327F1FE1CBD894FE1E82),(04FFF1E000BDE5DA50D4071D9A7D9EB2),(04FFF370008ED6E963E7342EA94E9EB1),(04FFFCD000EBF1FE16D7452FEE1B27AC)]," +
"[(04FFF0D0000418ED6E963E7342EA7A09),(04FFF3900085467F1FE1CBD894FE1E82)," +
"(04FFFEA000854A7F1FE1CBD894FE1E82),(04FFF89000BDE5DA50D4071D9A7D9EAC),(04FFF0000085527F1FE1CBD894FE1E82),(04FFFAB0009FC7F872F6253FB85F9EAA),(04FFFC2000D7E37C30720B175CB79EA9),(04FFF0E000F3B0BF0E9AC86BFF0327AA)]}";
MatchCollection match = Regex.Matches(dataStr, @"\[.*?\]"); ///获取读到的行数
MatchCollection matches;
int idx = 0;
Dictionary<int, string> Tag = new Dictionary<int, string>();
for (int k = 0; k < match.Count; k++)
{
matches = Regex.Matches(match[k].Value, @"\(.*?\)");
for (int m = 0; m < matches.Count; m++)
{
idx++;
string value = matches[m].Value.Trim(new char[] { '(', ')' });
Tag.Add(idx, value);
}
}