比如[Show],如何取出中括号中的"Show"字符?

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.Text;
    using System.Text.RegularExpressions;public class MyClass
    {
    public static void Main()
    {
    string str = "[Show]";
    Regex r;
    string pattern = "";
    pattern = @"\[(?<A>(.)*)\]"; r = new Regex( pattern ,
    RegexOptions.IgnoreCase|RegexOptions.Compiled); str = r.Replace( str, "${A}" );
    Console.Write(str); RL();
    }

    private static void WL(string text, params object[] args)
    {
    Console.WriteLine(text, args);
    }

    private static void RL()
    {
    Console.ReadLine();
    }

    private static void Break() 
    {
    System.Diagnostics.Debugger.Break();
    }
    }
      

  2.   

    Regex myReg=new Regex(@"(?<=\[)(\S*)(?=\])");
    用这个就行了