zoukankan      html  css  js  c++  java
  • 关于正则表达式

    正则表达式:英文Regular Expression)在计算机科学中,是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。
    如下的例子中的正则表达式是用来查询符合要求的body里的所以内容,在textbox1中输入您要查询内容所属的地址,textbox2中得到符合要求的查询结果,button2用来将查询到的结果保存到您要保存的地方!
      protected void Button1_Click(object sender, EventArgs e)
            {
               
                Regex reg = new Regex(@"<body>(.*\s)*.*</body>",RegexOptions.IgnoreCase );//正则表达式
              gethtml(this.TextBox1 .Text );
                string tem = this.TextBox2.Text;
                if (reg.IsMatch(tem))
                {
                    this.TextBox2.Text=reg.Match(tem).ToString();
                }
            }
            public void gethtml(string url)  //根据地址得到想要的结果
         {
                WebRequest request = WebRequest.Create(url );
                WebResponse response = request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(),                                 System.Text.Encoding.GetEncoding("gb2312"));
                this.TextBox2.Text = sr.ReadToEnd().ToString();
            }

            protected void Button2_Click(object sender, EventArgs e)//将得到的结果保存到指定的位置
          {
                FileStream fs = new FileStream(@"F:\haha.txt", FileMode.Create );
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(this.TextBox2.Text);
                sw.Close();
                fs.Close();

               }

  • 相关阅读:
    imperva_waf导入ssl证书
    博科光纤交换机初始化配置
    xss测试代码
    生成树注意事项
    [转载]Basics of the Unix Philosophy
    [转载]GSview注册码
    [转载]tar命令详解
    [转载]WinEdt 6 注册 试用期30天永不过期
    [转载+修改]计数排序
    [转载]C++ 关于声明,定义,类的定义,头文件作用,防止头文件在同一个编译单元重复引用,不具名空间
  • 原文地址:https://www.cnblogs.com/paper/p/1535202.html
Copyright © 2011-2022 走看看