如题:我有一个字符串如:dfad(任意字符串A)[$Begin$](任意字符传B)[$End$](任意字符串C)
现要获得[$Begin$]和[$End$]之间的(任意字符串B)
怎么做?我正则操作比较昏,希望给个详细点的操作.

解决方案 »

  1.   

    str=Regex.Match("Begin1234abcdEnd",@"(?<=Begin).*(?=End)").Value;
      

  2.   

    用正则:using System.Text.RegularExpressions;string test = "dfad(任意字符串A)[$Begin$](任意字符传B)[$End$](任意字符串C)";
    Match m = Regex.Match(test, @"(?<=\[\$Begin\$\])(.*)(?=\[\$End\$\])", RegexOptions.IgnoreCase);
    if (m.Success) Response.Write(m.Value);
      

  3.   

    我正则也比较晕, 不过如果[$Begin$] [$End$]仅出来一次的话, 用substring 也很方便
            string test = "dfad(任意字符串A)[$Begin$](任意字符传B)[$End$](任意字符串C)";
            int startIndex = test.IndexOf("[$Begin$]") + "[$Begin$]".Length;
            string a = test.Substring(startIndex, test.IndexOf("[$End$]") - startIndex);
            Response.Write(a);
      

  4.   

    @"(?<=\[\$Begin\$\])(.[^\$]*)(?=\[\$End\$\])",
    想必你不指一个这种配套标签 我再稍作补充 ^_^