zoukankan      html  css  js  c++  java
  • 正则表达式(分组取名)

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text.RegularExpressions;
    using System.Text;
    using System.IO;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        
           
            Regex r1 = new Regex("<td[^>]*>(?<play>([^<]*))<br />[^>]*>[^<]*</a>[^<]*</td>[^<]*<td[^>]*>[^<]*<a[^\\?]*\\?gid=(?<id>([^&]*))&amp;concede=(?<code>([^>]*))>(?<pl>([^<]*)[^<]*)</a>[^<]*</td>");

           // Regex r1 = new Regex(@"<td[^>]*>([^<]*)<br />[^>]*>[^<]*</a>[^<]*</td>[^<]*<td[^>]*>[^<]*<a[^\?]*\?gid=([^&]*)&amp;concede=([^>]*)>([^<]*)[^<]*</a>[^<]*</td>");
            string tabale = getTable();
           tabale=tabale.Replace("\n", "");
            MatchCollection list = r1.Matches(tabale);
            for (int i = 0; i < list.Count; i++)
            {
                Response.Write("&nbsp;&nbsp;play:" + list[i].Groups["play"].Value + "    &nbsp;&nbsp;&nbsp;&nbsp; id:" + list[i].Groups["id"].Value + "   &nbsp;&nbsp;&nbsp;&nbsp; code:" + (list[i].Groups["code"].Value.EndsWith("\"") ? list[i].Groups["code"].Value.Substring(0, list[i].Groups["code"].Value.Length - 1) : list[i].Groups["code"].Value )+ "   &nbsp;&nbsp;&nbsp;pl:" + list[i].Groups["pl"].Value + "<br/>");
            }
        }

        private string getTable()
        {

            return File.OpenText( Server.MapPath("TextFile.txt")).ReadToEnd();
        }

        /// <summary>
        /// 获得HTML代码开始标记和结束标记中间的数据
        /// </summary>
        /// <param name="code">HTML代码</param>
        /// <param name="wordsBegin">开始标记</param>
        /// <param name="wordsEnd">结束标记</param>
        /// <returns></returns>
        public string SniffwebCode(string code, string wordsBegin, string wordsEnd)
        {
            string NewsTitle = "";
            Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
            {
                NewsTitle = match1.Groups["title"].ToString();
            }
            return NewsTitle;
        }

    }

  • 相关阅读:
    Virtual Drive Manager V1.3.2(小巧实用的虚拟光驱)绿色版
    WimTool(Wim映像处理工具) V1.30.2011.501 免费绿色版
    WinHex V18.7(16进制编辑器) 多国语言绿色版
    WinSnap屏幕截图 V4.5.6 官方最新版
    Wsyscheck(系统检测维护工具) v1.68.33绿色版
    XueTr 0.45 (手工杀毒辅助工具) 绿色版
    Colorful(Folders星语多彩文件夹) v1.7绿色版
    飞雪桌面日历软件 V8.6 免费绿色版
    Notepad++ V6.9.0 中文绿色便携版
    屏幕尺子(电脑尺子) 1.0 免费绿色版
  • 原文地址:https://www.cnblogs.com/luluping/p/1534327.html
Copyright © 2011-2022 走看看