如何将txsTbl[uf08%w]字符串中[]之间的字符串用正则表达式替换成指定的其它串?谢谢.

解决方案 »

  1.   

    txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]
    如何将上面这个串的指定的某一部分,比如是txsDbl[abc001]或txsCateId[245]中[]中的字符串替换成其它指定的字符串?谢谢...
      

  2.   

    string s="txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]";
    Regex r = new Regex(@"\[[^\]]*?(?<content>[\s\S]*?)\]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
    MatchCollection mc =r.Matches(s);
    for(int i=0;i<mc.Count;i++)
    {
    string tmp="["+mc[i].Groups["content"].Value+"]";
    s=s.Replace(tmp,i.ToString());
    }
    MessageBox.Show(s);
    txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]改成了txsTbl0txsDbl1txsCateId2
    完全想怎么换就怎么换,可以了吧