日期:2014-05-17  浏览次数:21277 次

正则表达式拆分成数组
string a="PT<0101,Field>*PT<010203,MonthSum>+345*(PT<0101,Field>+PT<01091,Field>)"


拆分成如下数组:PT<0101,Field>
              PT<010203,MonthSum>
              PT<0101,Field>
              PT<01091,Field>


       
      大虾些只有40分
正则表达式,拆分,成数组

------解决方案--------------------
string a = "PT<0101,Field>*PT<010203,MonthSum>+345*(PT<0101,Field>+PT<01091,Field>)";
string[] result = Regex.Matches(a, @"PT\<\d+\,\w+?\>").Cast<Match>().Select(x => x.Value).ToArray();
------解决方案--------------------
string[] result = Regex.Matches(a, @"(?<=PT<)[^<>]+(?=>)").OfType<Match>().Select(x => x.Value).ToArray();
            

------解决方案--------------------
引用:
"0101,Field"
"010203,MonthSum"
"0101,Field"
"01091,Field"

大虾如果拆分成这种呢


string[] result = Regex.Matches(a, @"PT\<(\d+\,\w+?)\>").Cast<Match>().Select(x => x.Groups[1].Value).ToArray();