using System.Text.RegularExpressions;

/// <summary>
        /// 执行正则提取出值
        /// </summary>
        /// <param name="RegexString">正则表达式</param>
        /// <param name="HtmlCode">HtmlCode源代码</param>
        /// <returns>数组</returns>
        public static string[] GetRegValueAarry(string RegexString, string HtmlCode)
        {
            string[] MatchVale = new String[30];//初始化数组
            int i = 0;
            Regex r = new Regex(RegexString);

for (Match m = r.Match(HtmlCode); m.Success; m = m.NextMatch())
            {
                MatchVale[i] = m.Value.ToString();
                i++;
            }

return MatchVale;
        }

/// <summary>
        /// 获取标签内的内容(只取出第一个)
        /// </summary>
        /// <param name="code"></param>
        /// <param name="wordsBegin"></param>
        /// <param name="wordsEnd"></param>
        /// <returns></returns>
        public static string SniffwebCode(string code, string wordsBegin, string wordsEnd)
        {
            string NewsTitle = "";
            Regex regex1 = new Regex("" + wordsBegin + @"(?<content>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
            {
                NewsTitle += match1.Groups["content"].ToString();
                break;
            }
            return NewsTitle;
        }

// <summary>
        /// 获取标签内的内容并用~连上
        /// </summary>
        /// <param name="code"></param>
        /// <param name="wordsBegin"></param>
        /// <param name="wordsEnd"></param>
        /// <returns></returns>
        public static string SniffwebCodeSplit(string code, string wordsBegin, string wordsEnd)
        {
            string NewsTitle = "";
            Regex regex1 = new Regex("" + wordsBegin + @"(?<content>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
            {
                NewsTitle += match1.Groups["content"].ToString() + "~";
            }
            return NewsTitle;
        }

C#正则_取出标签内的内容(非贪婪)的更多相关文章

  1. javascript 获取标签内的内容

    js 获取标签内的内容 参考:这篇博客给了我很大的启发. http://www.cnblogs.com/breakdown/archive/2012/10/09/2716221.html 我遇到的问题 ...

  2. CSS标签内多余内容隐藏

    CSS: <style> .mazey{width:100px;} .nowrap{overflow:hidden;text-overflow:ellipsis;white-space:n ...

  3. 总结php删除html标签和标签内的内容的方法

    来源:https://www.cnblogs.com/shaoguan/p/7336984.html 经常扒别人网站文章的坑们:我是指那种批量式采集的压根不看内容的:少不了都会用到删除html标签的函 ...

  4. xpath提取目录下所有标签内的内容,递归 //text()

    利用xpath来提取所有标签里面的内容,即使标签头不同 #-*-coding:utf8-*- import re import os from lxml import etree html = ''' ...

  5. 正则匹配抓取input 隐藏输入项和 <td>标签内的内容

    这里不多作解释了,只要提供方法,如果想了解正则匹配,就去百度. 第一条是,匹配出所有的隐藏输入域 $patern = "/<input(.*?)type=\"hidden\& ...

  6. td标签内的内容过长导致的问题的解决办法

    问题描述:在开发过程中,td标签中的有一个cell格中的内容过长,导致td标签高度增加,从而导致整个页面内容的不协调:

  7. PHP 替换标签和标签内的内容

    $filter_arr=array('/#(.*?)#/','/\$(.*?)\$/','/\^(.*?)\^/');//要替换的标签 $content=$data['Monthlys']['cont ...

  8. javascript 获取 class 样式 重新赋值class样式 为div等系列标签内更改内容

    name = document.getElementById(project_not_through_id).className;                     // 获取目标id的 cla ...

  9. 利用正则取出Stirng中“”引号内的内容

    // 取出所有""中间的内容,正则如下 Pattern pattern1 = Pattern.compile("(?<=\")([\\S]+?)(?=\& ...

随机推荐

  1. mysql 使用如下三种方式应用where条件,从好到坏

    在索引中使用where条件过滤不匹配的记录,这是在存储引擎层完成的: ​使用索引覆盖扫描(explain语句中的Extra列中出现Using index)来返回记录.直接从索引中过滤掉不需要的记录并返 ...

  2. .net配置404错误页面

    如果你的网站出现一堆让人看不懂的报错,那么你就不是一个合格的程序员,也不是一个合格的站长. 下面的方面可以帮助你的网站远离让人头大的页面. 第一步:配置web.config 打开web.config, ...

  3. thinkphp中 volist循环的 mod取值的问题

    <ul> <volist name="data" id="arr" key="k" mod="2"&g ...

  4. lampp and testrail

    https://wyzx.testrail.net szllq2000 http://129.0.1.228/testrail/ http://docs.gurock.com/testrail-adm ...

  5. ios开发 内测包添加测试UDID

    内侧包添加 UDID: 1.蒲公英获取设备UDID  https://www.pgyer.com/udid 2. 登录开发者中心   --> Certificates, Identifiers ...

  6. TA-Lib中文文档(二):talib安装

    安装 使用pip安装 PyPI: $ pip install TA-Lib Or checkout the sources and run setup.py yourself: $ python se ...

  7. django-mvc

    而对于真实开发中的python web程序来说,一般会分为两部分:服务器程序和应用程序.服务器程序负责对socket服务器进行封装,并在请求到来时,对请求的各种数据进行整理.应用程序则负责具体的逻辑处 ...

  8. python-pdf添加水印

    0.用到两个扩展模块:ReportLab.PyPDF2. 1.创建水印PDF. 1).创建文字水印pdf文件 代码: #encoding=utf-8 #author: walker #date: 20 ...

  9. java-mybaits-00801-逆向工程

    1.1     什么是逆向工程 参看地址:http://www.mybatis.org/generator/index.html 使用官方网站的mapper自动生成工具mybatis-generato ...

  10. vs2010中如何编写C语言程序

    File->New->Project 在打开的New Project对话框中最左侧一栏中选择Visual C++下面的CLR,之后在其右侧的区域中选择CLR Empty Applicati ...