C#用正则实现简单的报表标记

 
string test = "<rpt:tag name=rpt1 col=1 row=2 order=asc>abcsadf </rpt:tag> aaa  <rpt:tag name=rpt2 col=4 row=10 order=desc>abcsadf </rpt:tag>";
MatchCollection mc = Regex.Matches(test, @"<rpt:tag[^>]*>", RegexOptions.IgnoreCase);
int z = 0;
foreach (Match m in mc)
{
    txt.Text += "第" + ++z + "个tag的属性:\n";
    MatchCollection mcList = Regex.Matches(m.Value, @"([^\s=]+)=([^\s>]+)", RegexOptions.IgnoreCase);
    foreach (Match mList in mcList)
    {
        txt2.Text += "属性: " + mList.Groups[1].Value + "  值: " + mList.Groups[2].Value + "\n";
    }
}

 

你可能感兴趣的:(C#)