有以下这么一段文本_text,我需要分解成为这样一个东西: this  hyButton4 ResourceID frmResEditor_hyButton4四个匹配项,请问如何写这个正则表达式?
 string _text = "this.hyButton4.ResourceID = \"frmResEditor_hyButton4\";";

解决方案 »

  1.   


    //正则表达式:^([^\s]+)\s*\.\s*([^\s]+)\s*\.\s*([^\s]+)\s*=\s*"([^"]+)"\s*;$string _text = "this.hyButton4.ResourceID   =   \"frmResEditor_hyButton4\";";
    Regex re = new Regex(@"^([^\s]+)\s*\.\s*([^\s]+)\s*\.\s*([^\s]+)\s*=\s*""([^""]+)""\s*;$");
    Match m = re.Match(_text);
    //分别获取四个匹配项
    //m.Groups[1].Value
    //m.Groups[2].Value
    //m.Groups[3].Value
    //m.Groups[4].Value
      

  2.   


    static void Main()
    {
                string str = "string   _text   =   'this.hyButton4.ResourceID   =   \"frmResEditor_hyButton4\";';";
                string value = str.Substring(str.IndexOf("'"));
                string[] strs = Regex.Split(value, @"[^\d|^\w]");
                string[] strsReturn = new string[4];
                int i = 0;
                foreach (string s in strs)
                {
                    if(! (s.Trim().Equals("")))
                    {
                        strsReturn[i] = s;
                        i++;
                    }
                }
                foreach (string s in strsReturn)
                {
                    Console.WriteLine(s);
                }
                Console.ReadKey();
    }
      

  3.   

    没搞清什么意思!如果就那么多内容的话,应该可以写死
    "[(this)|(hyButton4)|(ResourceID)|(frmResEditor_hyButton4)]+"
      

  4.   

    呵呵,我自己也写好了一个。
    "this.(?<ctrlname>[^.].*?)\\.(?<ctrltype>[ResourceID|Text|Name].*?)\\s=\\s\"(?<ctrltext>[^\"].*?)\"$";散分。