Db[exdb]Tbl[extbl]CategoryId[12]ContextId[245]如何将此串根据[]部分分离出来,谢谢.
分离的效果如下,一定要分离成数组,便于我在程序中识别;一定要用正则表达式,这样效率会高一些,谢谢:第一次分离结果:
Db[exdb]
Tbl[extbl]
CategoryId[12]
ContextId[245]第二次分离结果:
Db  exdb
Tbl  extbl
CategoryId  12
ContextId 245

解决方案 »

  1.   

    string pattern = @"*?]";
      

  2.   

    一次就能分离了:
    string s="Db[exdb]Tbl[extbl]CategoryId[12]ContextId[245]";
    string[] ss=s.Split(new char[]{'[',']'});
    string rs="";
    foreach(string p in ss)
    {
    rs+=p+"\n";
    }
    MessageBox.Show(rs);
      

  3.   

    CSDN出问题了,我回贴和我说的不一样了?
    string s="Db[exdb]Tbl[extbl]CategoryId[12]ContextId[245]";
    string[] ss=s.Split(new char[]{'[',']'});
    string rs="";
    foreach(string p in ss)
    {
    rs+=p+"\n";
    }
    MessageBox.Show(rs);//哦为了查看ss内容
      

  4.   

    怎么还是这样?
    string s="Db[exdb]Tbl[extbl]CategoryId[12]ContextId[245]";
    string[] ss=s.Split(new char[]{'[',']'});
    string rs="";
    foreach(string p in ss)
    {
    rs+=p+"\n";
    }
    MessageBox.Show(rs);
      

  5.   

    在你另一贴中给你回答了:
    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
    完全想怎么换就怎么换,可以了吧
      

  6.   

    string s = "txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]";
    Match um = Regex.Match(s, @"^[\S\s]*Dbl\[[\S\s]*\]");//查找类似Dbl[xxx]的字符串。
    if(um.Success)//如果存在
    {
      string RegStr="#AAAAAA";
      //将Dbl[xxx]中的xxx替换成指定串RegStr,这里的正则表达式怎么写?谢谢。我写的不对。
      Response.Write(Regex.Replace(um.ToString(), @"(?=Tbl[)([\S|\s]*)(?=])", RegStr));
    }
      

  7.   

    看到了你给我的留言,你试试我下面的代码:
    string s="txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]Dbl[]";
    string s1,pat=@"Dbl\[[\s\S]*?\]";
    s1=Regex.Replace(s,pat,"123456");
    123456你可以改成你的字符串,S1就是你要的了
      

  8.   

    string s="txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]Dbl[]";
    string s1,pat=@"txsDbl\[[\s\S]*?\]";
    s1=Regex.Replace(s,pat,"123456");这样,得到的结果是:
    txsTbl[uf08%w]123456txsCateId[245]Dbl[];
    我希望的结果是:
    txsTbl[uf08%w]txsDbl[123456]txsCateId[245]Dbl[]
    应该怎么做?
      

  9.   

    string s="txsTbl[uf08%w]txsDbl[abc001]txsCateId[245]Dbl[]";
    string s1,pat=@"Dbl\[[\s\S]*?\]";
    s1=Regex.Replace(s,pat,"Dbl["+"123456"+"]");