zoukankan      html  css  js  c++  java
  • 解决C#识别变量定义的正则表达式

     Collection collection = new Collection();
                collection.Coding = "GB2312";
                string HtmlCode = collection.ReaderHTMLCode("http://www.qqtu88.com/qqjq/index.html");
                string pageurl = "http://www.qqtu88.com/qqjq/QQkongjianjishu/2011/0806/27479.html
    ";
                string pReg = "
    \\d+";
                string Link_str = "";
                Uri u = new Uri(pageurl);
                pageurl = pageurl.ToLower().Replace("http://", "").Replace(u.Host.ToString().ToLower(), "");
                pageurl = Regex.Replace(pageurl, pReg, "\\\\d+");
                pageurl = pageurl.Replace(".", "\\\\.");
                Label1.Text = pageurl;
                MatchCollection m = Regex.Matches(HtmlCode.ToLower(), Regex.(pageurl));
                for (int c = 0; c <= m.Count - 1; c++)
                {
                    string strNew = m[c].ToString();
                    // 过滤重复的URL 
                    if (Link_str.IndexOf(strNew) == -1)
                    {
                        Link_str += "http://" + u.Host + strNew + ",";
                    }
                }
                TextBox1.Text = Link_str;

    最主要的是Regex.这个函数可以对变量中的转义字符进行转义

    下面方法也可以

     Collection collection = new Collection();
                collection.Coding = "GB2312";
                string HtmlCode = collection.ReaderHTMLCode("http://www.qqtu88.com/qqjq/index.html");
                string pageurl = "http://www.qqtu88.com/qqjq/QQkongjianjishu/2011/0806/27479.html";
                string pReg = "\\d+";
                string Link_str = "";
                Uri u = new Uri(pageurl);
                pageurl = pageurl.ToLower().Replace("http://", "").Replace(u.Host.ToString().ToLower(), "");
                pageurl = Regex.Replace(pageurl, pReg, "\\d+");
                pageurl = pageurl.Replace(".", "\\.");
                Label1.Text = pageurl;
                Regex r = new Regex(pageurl , RegexOptions.IgnoreCase);
                MatchCollection m = r.Matches(HtmlCode.ToLower());
                for (int c = 0; c <= m.Count - 1; c++)
                {
                    string strNew = m[c].ToString();
                    // 过滤重复的URL 
                    if (Link_str.IndexOf(strNew) == -1)
                    {
                        Link_str += "http://" + u.Host + strNew + ",";
                    }
                }
                TextBox1.Text = Link_str;

  • 相关阅读:
    SQLMAP注入教程-11种常见SQLMAP使用方法详解
    VS2012/2013/2015/Visual Studio 2017 关闭单击文件进行预览的功能
    解决 IIS 反向代理ARR URLREWRITE 设置后,不能跨域跳转 return Redirect 问题
    Spring Data JPA one to one 共享主键关联
    JHipster 问题集中
    Spring Data JPA 定义超类
    Spring Data JPA查询关联数据
    maven命名
    maven仓库
    Jackson读取列表
  • 原文地址:https://www.cnblogs.com/yeye518/p/2231621.html
Copyright © 2011-2022 走看看