嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
REG正则表达式试验程序.rar
	
程序由Visual C#编写,用于学习和演示正则表达式的使用, 程序主要涉及Regex类和Match类的通常用法。
	
	private void button1_Click(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    string[] rst = new string[2], rs = new string[2],str = new string[textBox1.Lines.Length];
                    if (Rtxt.Contains("|")) { rs = Rtxt.Split('|'); rst = Rstr.Split('|'); }                    
                    for (int i = 0; i < textBox1.Lines.Length; i  )
                    {
                        if (textBox1.Lines[i]!="")
                        {
                            if (Rtxt.Contains("|"))
                            {
                                if (Regex.IsMatch(textBox1.Lines[i], rst[0]))
                                    str[i] = textBox1.Lines[i]   "  是"   rs[0];
                                else if (Regex.IsMatch(textBox1.Lines[i], rst[1]))
                                    str[i] = textBox1.Lines[i]   "  是"   rs[1];
                                else str[i] = textBox1.Lines[i]   "  不是"   Rtxt.Replace("|", "或");
                            }
                            else
                            {
                                if (Regex.IsMatch(textBox1.Lines[i], Rstr))
                                    str[i] = textBox1.Lines[i]   "  是"   Rtxt;
                                else str[i] = textBox1.Lines[i]   "  不是"   Rtxt;
                            } 
                        }
                    }
                    textBox3.Lines = str;
                    break;
                case 1:
                    Match match;
                    string str1="找到重复:\r\n";
                    for (int i = 0; i < textBox1.Lines.Length; i  )
                    {
                        if (textBox1.Lines[i] != "")
                        {
                            match = Regex.Match(textBox1.Lines[i], Rstr);
                            while (match.Success)
                            {
                                str1 ="第" (i 1) "行:在位置" match.Groups[2].Index  "处发现重复的" Rtxt   match.Groups[1].Value  "\r\n";
                                match = match.NextMatch();
                            }
                        }
                    }
                    textBox3.Text = str1;
                    break;
                case 2:
                    MatchCollection matches; str1=null;
                    Regex r = new Regex(Rstr);
                    for (int i = 0; i < textBox1.Lines.Length; i  )
                    {
                        matches = r.Matches(textBox1.Lines[i]);
                        foreach (Match matchi in matches)
                        {
                            str1  = "第"   (i   1)   "行:在位置"   matchi.Index   "处找到"   Rtxt  " "  matchi.Value   "\r\n";
                        }
                    }
                    textBox3.Text = str1;
                    break;
                case 3:
                    str1 = "";
                    for (int i = 0; i < textBox1.Lines.Length; i  )
                    {
                        str1  = Regex.Replace(textBox1.Lines[i], Rstr, textBox4.Text)  "\r\n";
                    }
                    textBox3.Text = str1;
                    break;
                case 4:
                    str1 = "";
                    for (int i = 0; i < textBox1.Lines.Length; i  )
                    {
                        str1  = "第"   (i   1)   "行分割结果:\r\n";
                        foreach (string item in Regex.Split(textBox1.Lines[i], Rstr))
                        {
                            if (!String.IsNullOrEmpty(item))
                                str1  = item  "\r\n"; 
                        }
                    }
                    textBox3.Text = str1;
                    break;                
            }
         }