日期:2014-05-17 浏览次数:20775 次
string A = "a bb 1 bb 1 2 bb 1 -7.0 3 cc 1 cc 1 2 cc 1 2 3 "; string B = "bb"; int index = 2; int strIndex = 3; Regex reg = new Regex(string.Format(@"(?:\s{0}(?:\s[\d.-]*)*){{{1}}}\s{0}(\s[\d.-]+)+", B, strIndex - 1)); Console.WriteLine(reg.Match(A).Groups[1].Captures[index - 1].Value); ================================================================================ A = " a aa aa aa aa aa aa 0.1 0.2 -0.3 4 5 6.0 -7.0"; B = "aa"; index = 7; strIndex = 5; reg = new Regex(string.Format(@"(?:\s{0}(?:\s[\d.-]*)*){{{1}}}\s{0}(\s[\d.-]+)+", B, strIndex - 1)); Console.WriteLine(reg.Match(A).Groups[1].Captures[index - 1].Value);
------解决方案--------------------