Matches正则使用提取内容
用VS新建WinForm程序,窗体上是三个文本框和一个按钮。
可以自己构造正则表达式,自己修改匹配内容
正则表达是要提取的部分为hewenqitext
代码如下:
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms; namespace HoverTreeBatch.HoverTree
{
public partial class RegexForm : Form
{
public RegexForm()
{
InitializeComponent();
textBox_regex.Text = @"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<hewenqitext>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>";
textBox_content.Text = @"<div class=""dengxaing-hovertree-com""><a title=""何问起批量2"" href=""http://hovertree.com/hvtimg/201601/p3t2ldyr.png""><img src=""http://hovertree.com/hvtimg/201601/p3t2ldyr_l.png"" style=""width:180px;height:140px;"" /></a><a title=""VS2015开发人员命令提示查看PublicKeyToken(公钥标记)"" href=""http://hovertree.com/hvtimg/201601/wn0bamxp.png""><img src=""http://hovertree.com/hvtimg/201601/wn0bamxp_l.png"" style=""width:180px;height:140px;"" /></a><a title=""消灭僵尸游戏"" href=""http://hovertree.com/hvtimg/201601/q47add2k.jpg""><img src=""http://hovertree.com/hvtimg/201601/q47add2k_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""纯CSS3漂亮的房子不错的天气"" href=""http://hovertree.com/hvtimg/201601/lbau8hqb.png""><img src=""http://hovertree.com/hvtimg/201601/lbau8hqb_l.png"" style=""width:180px;height:140px;"" /></a><a title=""HoverClock"" href=""http://hovertree.com/hvtimg/201601/thbniyjx.png""><img src=""http://hovertree.com/hvtimg/201601/thbniyjx_l.png"" style=""width:180px;height:140px;"" /></a><a title=""javascript元旦倒计时特效"" href=""http://hovertree.com/hvtimg/201512/o9qashmi.gif""><img src=""http://hovertree.com/hvtimg/201512/o9qashmi_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""下雨"" href=""http://hovertree.com/hvtimg/201512/f748s0ko.jpg""><img src=""http://hovertree.com/hvtimg/201512/f748s0ko_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""何问起直接说喜欢你!"" href=""http://hovertree.com/hvtimg/201512/vt1tf0xl.jpg""><img src=""http://hovertree.com/hvtimg/201512/vt1tf0xl_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""IIS7,IIS7.5 URL重写模块工具"" href=""http://hovertree.com/hvtimg/201512/ew4yb78b.png""><img src=""http://hovertree.com/hvtimg/201512/ew4yb78b_l.png"" style=""width:180px;height:140px;"" /></a><a title=""山水画"" href=""http://hovertree.com/hvtimg/201512/agagq0or.jpg""><img src=""http://hovertree.com/hvtimg/201512/agagq0or_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""刘德华"" href=""http://hovertree.com/hvtimg/201512/r51a22uy.gif""><img src=""http://hovertree.com/hvtimg/201512/r51a22uy_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""IIS为网站设置域名"" href=""http://hovertree.com/hvtimg/201512/69yoeuhf.jpg""><img src=""http://hovertree.com/hvtimg/201512/69yoeuhf_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""HoverTreeCMS分成"" href=""http://hovertree.com/hvtimg/201512/jgi94fdf.png""><img src=""http://hovertree.com/hvtimg/201512/jgi94fdf_l.png"" style=""width:180px;height:140px;"" /></a><a title=""范冰冰"" href=""http://hovertree.com/hvtimg/201511/6j9j6tk5.png""><img src=""http://hovertree.com/hvtimg/201511/6j9j6tk5_l.png"" style=""width:180px;height:140px;"" /></a><a title=""周末愉快"" href=""http://hovertree.com/hvtimg/201511/60mj4wsb.gif""><img src=""http://hovertree.com/hvtimg/201511/60mj4wsb_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""谢霆锋手机背景图"" href=""http://hovertree.com/hvtimg/201508/cnvkv745.jpg""><img src=""http://hovertree.com/hvtimg/201508/cnvkv745_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""现代舞舞蹈家玛莎·葛兰姆动画Logo"" href=""http://hovertree.com/hvtimg/201506/ufigfjvn.jpg""><img src=""http://hovertree.com/hvtimg/201506/ufigfjvn_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""每次吵架,都希望男票这样解决战斗。。。"" href=""http://hovertree.com/hvtimg/201506/iqoqrhfn.gif""><img src=""http://hovertree.com/hvtimg/201506/iqoqrhfn_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""现代舞舞蹈家玛莎·葛兰姆动画Logo"" href=""http://hovertree.com/hvtimg/201506/xlyxp4wg.png""><img src=""http://hovertree.com/hvtimg/201506/xlyxp4wg_l.png"" style=""width:180px;height:140px;"" /></a><a title=""美女"" href=""http://hovertree.com/hvtimg/201506/m921jw4n.jpg""><img src=""http://hovertree.com/hvtimg/201506/m921jw4n_l.jpg"" style=""width:180px;height:140px;"" /></a></div>";
} private void button_ok_Click(object sender, EventArgs e)
{
Regex m_hvtRegImg = new Regex(textBox_regex.Text, RegexOptions.IgnoreCase); //搜索匹配的字符串
MatchCollection hewenqi_matches;
try
{
hewenqi_matches = m_hvtRegImg.Matches(textBox_content.Text); // 取得匹配项列表
foreach (Match match in hewenqi_matches)
{
textBox_result.Text = textBox_result.Text + match.Groups["hewenqitext"].Value + "\r\n";
}
}
catch (Exception ex)
{
textBox_result.Text = ex.ToString();
} }
}
} /*
<div class="dengxaing-hovertree-com"> <a title="何问起批量2" href=""http://hovertree.com/hvtimg/201601/p3t2ldyr.png"">
<img src=""http://hovertree.com/hvtimg/201601/p3t2ldyr_l.png"" style="width:180px;height:140px;" /></a> <a title="VS2015开发人员命令提示查看PublicKeyToken(公钥标记)" href=""http://hovertree.com/hvtimg/201601/wn0bamxp.png"">
<img src=""http://hovertree.com/hvtimg/201601/wn0bamxp_l.png"" style="width:180px;height:140px;" /></a> <a title="消灭僵尸游戏" href=""http://hovertree.com/hvtimg/201601/q47add2k.jpg"">
<img src=""http://hovertree.com/hvtimg/201601/q47add2k_l.jpg"" style="width:180px;height:140px;" /></a> <a title="纯CSS3漂亮的房子不错的天气" href=""http://hovertree.com/hvtimg/201601/lbau8hqb.png"">
<img src=""http://hovertree.com/hvtimg/201601/lbau8hqb_l.png"" style="width:180px;height:140px;" /></a> <a title="HoverClock" href=""http://hovertree.com/hvtimg/201601/thbniyjx.png"">
<img src=""http://hovertree.com/hvtimg/201601/thbniyjx_l.png"" style="width:180px;height:140px;" /></a> <a title="javascript元旦倒计时特效" href=""http://hovertree.com/hvtimg/201512/o9qashmi.gif">
<img src=""http://hovertree.com/hvtimg/201512/o9qashmi_l.gif" style="width:180px;height:140px;" /></a> <a title="下雨" href=""http://hovertree.com/hvtimg/201512/f748s0ko.jpg"">
<img src=""http://hovertree.com/hvtimg/201512/f748s0ko_l.jpg"" style="width:180px;height:140px;" /></a> <a title="何问起直接说喜欢你!" href=""http://hovertree.com/hvtimg/201512/vt1tf0xl.jpg"">
<img src=""http://hovertree.com/hvtimg/201512/vt1tf0xl_l.jpg"" style="width:180px;height:140px;" /></a> <a title="IIS7,IIS7.5 URL重写模块工具" href=""http://hovertree.com/hvtimg/201512/ew4yb78b.png"">
<img src=""http://hovertree.com/hvtimg/201512/ew4yb78b_l.png"" style="width:180px;height:140px;" /></a> <a title="山水画" href=""http://hovertree.com/hvtimg/201512/agagq0or.jpg"">
<img src=""http://hovertree.com/hvtimg/201512/agagq0or_l.jpg"" style="width:180px;height:140px;" /></a> <a title="刘德华" href=""http://hovertree.com/hvtimg/201512/r51a22uy.gif">
<img src=""http://hovertree.com/hvtimg/201512/r51a22uy_l.gif" style="width:180px;height:140px;" /></a> <a title="IIS为网站设置域名" href=""http://hovertree.com/hvtimg/201512/69yoeuhf.jpg"">
<img src=""http://hovertree.com/hvtimg/201512/69yoeuhf_l.jpg"" style="width:180px;height:140px;" /></a> <a title="HoverTreeCMS分成" href=""http://hovertree.com/hvtimg/201512/jgi94fdf.png"">
<img src=""http://hovertree.com/hvtimg/201512/jgi94fdf_l.png"" style="width:180px;height:140px;" /></a> <a title="范冰冰" href=""http://hovertree.com/hvtimg/201511/6j9j6tk5.png"">
<img src=""http://hovertree.com/hvtimg/201511/6j9j6tk5_l.png"" style="width:180px;height:140px;" /></a> <a title="周末愉快" href=""http://hovertree.com/hvtimg/201511/60mj4wsb.gif">
<img src=""http://hovertree.com/hvtimg/201511/60mj4wsb_l.gif" style="width:180px;height:140px;" /></a> <a title="谢霆锋手机背景图" href=""http://hovertree.com/hvtimg/201508/cnvkv745.jpg"">
<img src=""http://hovertree.com/hvtimg/201508/cnvkv745_l.jpg"" style="width:180px;height:140px;" /></a> <a title="现代舞舞蹈家玛莎·葛兰姆动画Logo" href=""http://hovertree.com/hvtimg/201506/ufigfjvn.jpg"">
<img src=""http://hovertree.com/hvtimg/201506/ufigfjvn_l.jpg"" style="width:180px;height:140px;" /></a> <a title="每次吵架,都希望男票这样解决战斗。。。" href=""http://hovertree.com/hvtimg/201506/iqoqrhfn.gif">
<img src=""http://hovertree.com/hvtimg/201506/iqoqrhfn_l.gif" style="width:180px;height:140px;" /></a> <a title="现代舞舞蹈家玛莎·葛兰姆动画Logo" href=""http://hovertree.com/hvtimg/201506/xlyxp4wg.png"">
<img src=""http://hovertree.com/hvtimg/201506/xlyxp4wg_l.png"" style="width:180px;height:140px;" /></a> <a title="美女" href=""http://hovertree.com/hvtimg/201506/m921jw4n.jpg"">
<img src=""http://hovertree.com/hvtimg/201506/m921jw4n_l.jpg"" style="width:180px;height:140px;" /></a>
</div>
*/
转载自:http://hovertree.com/h/bjaf/nxoqir0b.htm
http://www.cnblogs.com/sosoft/p/kaifajishu.html
Matches正则使用提取内容的更多相关文章
- pyhanlp 共性分析与短语提取内容详解
pyhanlp 共性分析与短语提取内容详解 简介 HanLP中的词语提取是基于互信息与信息熵.想要计算互信息与信息熵有限要做的是 文本分词进行共性分析.在作者的原文中,有几个问题,为了便于说明,这 ...
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
Visual Studio 2017中使用正则修改部分内容 最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效 ...
- java正则匹配 指定内容以外的 内容
今天,遇到一个需要 匹配出 指定内容以外的 内容的需求. 乍一看,需求貌视很简单啊,直接上 非贪婪模式的 双向零宽断言(有的资料上也叫 预搜索.预查.环视lookaround): 比如,我要匹配 串内 ...
- Word,Excel,pdf,txt等文件上传并提取内容
近期项目需求:1.要用到各种文件上传,下载. 2.并对文件进行搜索. 3.仅仅要文件里包括有搜索的内容,所有显示出来. 今天正好有时间整理一下,方便以后阅读,及对须要用到的朋友提供微薄之力.首先在实现 ...
- Visual Studio 2017中使用正则修改部分内容
最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效果如下 修改前: /// <summary> /// ...
- C#快速获取指定网页源码的几种方式,并通过字符串截取函数 或 正则 取指定内容(IP)
//只获取网页源码开始到标题位目的进行测试 //第一种方式经过测试,稍微快点 string url = "http://www.ip.cn"; HttpWebRequest req ...
- Asp.net正则获取html内容
1.获取div内容 string str = "tt<u>ss</u><div id=\"test\"><div>< ...
- C# 正则获取html内容
1.获取div内容 string str = "tt<u>ss</u><div id=\"test\"><div>< ...
- javascript 正则匹配 提取所有 preg_match_all matchAll方法
javascript 提取全部的的方法.javascript中没有matchAll这种方法. 用while来实现类似 PHP 中的preg_match_all() :(by default7#zbph ...
随机推荐
- 中间人攻击 -- Cookie 喷发
0x00 前言 分享个中间人攻击姿势,屡试不爽. 原本是篇老文,不过写的太啰嗦.今天用简明的文字,重新讲一遍. 0x01 原理 传统 cookie 嗅探,只能获得用户主动访问的站点.不访问就抓不到,效 ...
- 招聘.NET开发人员(截止于2015-06-15)
文章更新 2015-06-15 01:00AM: 感谢各位的支持,简历和解决方案接收截止.2015-06-08 08:30AM: 已经收到一些简历和解决方案,正在筛选中.职位仍然开放,欢迎发送简历及解 ...
- Hystrix框架3--线程池
线程池 在Hystrix中Command默认是运行在一个单独的线程池中的,线程池的名称是根据设定的ThreadPoolKey定义的,如果没有设置那么会使用CommandGroupKey作为线程池. 这 ...
- Android开发学习之路-回调机制学习笔记
不知道是我学Java的时候没有认真听还是怎么的,曾经一直不知道什么是“回调”,它有什么用,百度一大堆,都太复杂看不明白(好吧是我笨),所以想把自己理解的分享给其他看到的人,大家都真正认识一下这个重要的 ...
- android 画虚线,虚线圆
Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.set ...
- ThinkPHP3.2设置404跳转页面
在ThinkPHP3.2版本中当我们访问不存在的页面时会出现非常不友好错误提示页面,类如下图: 解决办法: 1.在ThinkPHP3.2详细的介绍了该框架下的ThinkPHP惯例配置文件convent ...
- 创建分区表和查看分区表的Metadata
未分区的表,只能存储在一个FileGroup中:对table进行分区后,每一个分区都存储在一个FileGroup中.表分区是将逻辑上一个完整的表,按照特定的字段拆分成Partition set,分散到 ...
- [转]浏览器退出之后php还会继续执行么?
原文链接:http://www.cnblogs.com/yjf512/p/5362025.html 前提:这里说的是典型的lnmp结构,nginx+php-fpm的模式 如果我有个php程序执行地非常 ...
- 被嫌弃的eval和with
× 目录 [1]eval [2]with 前面的话 eval和with经常被嫌弃,好像它们的存在就是错误.在CSS中,表格被嫌弃,在网页中只是用表格来展示数据,而不是做布局,都可能被斥为不规范,矫枉过 ...
- EntityFramework 7 更名为EntityFramework Core(预发布状态)
前言 最近很少去学习和探索新的东西,尤其是之前一直比较关注的EF领域,本身不太懒,但是苦于环境比较影响自身的心情,所以迟迟没有下笔,但是不去学习感觉在精神层面缺少点什么,同时也有园友说EF又更新了,要 ...