日期:2014-05-17 浏览次数:20726 次
string result = "\r[1]手机\r[2]电脑\r[3]母婴用品"; string match_pattern = @"^((\s|\r)*?(?<text>\[(?<value>\d+?)\][^\s\\]+)(\s|\r)*?)+$"; Match m = Regex.Match(result, match_pattern); if (m.Success)//匹配成功 { string[] arr = m.Groups["text"].Captures.Cast<Capture>().Select(a => a.Value).ToArray(); /* * [0] "[1]手机" string [1] "[2]电脑" string [2] "[3]母婴用品" string */ List<int> _list = m.Groups["value"].Captures.Cast<Capture>().Select(a => int.Parse(a.Value)).ToList(); /* * [0] 1 int [1] 2 int [2] 3 int */ }