字符串内容为 setuser("张三",19,"一年级")
怎样用正则表达式把 张三 19 一年级 提取出来?

解决方案 »

  1.   

    trystring yourStr = ..............;
    Match m = Regex.Match(yourStr, @"setuser\(""(?<name>[^""]*)"",(?<age>\d+),""(?<grade>[^""]*)""\)", RegexOptions.IgnoreCase);
    if (m.Success)
    {
        richTextBox2.Text += m.Groups["name"].Value + "\n";
        richTextBox2.Text += m.Groups["age"].Value + "\n";
        richTextBox2.Text += m.Groups["grade"].Value + "\n";
    }PS:楼主例子中的“)”为全角吧,是因为手动输入的问题,还是说源字符串就是这样
      

  2.   

    用正则不一定好啊
    strText = "setuser("张三",19,"一年级")";
    string strInfo = strText.SubString(strText.IndexOf("("));string[] strContext = strInfo.Slip(',');strContext[0] = "张三";
    strContext[1] = "19";
    strContext[2] = "一年级";