本文实例讲述了WinForm使用正则表达式提取内容的方法。分享给大家供大家参考,具体如下:

用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://localhost/hvtimg/201601/p3t2ldyr.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201601/p3t2ldyr_l.png"" style=""width:180px;height:140px;"" /></a><a title=""VS2015开发人员命令提示查看PublicKeyToken(公钥标记)"" href=""http://localhost/hvtimg/201601/wn0bamxp.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201601/wn0bamxp_l.png"" style=""width:180px;height:140px;"" /></a><a title=""消灭僵尸游戏"" href=""http://localhost/hvtimg/201601/q47add2k.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201601/q47add2k_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""纯CSS3漂亮的房子不错的天气"" href=""http://localhost/hvtimg/201601/lbau8hqb.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201601/lbau8hqb_l.png"" style=""width:180px;height:140px;"" /></a><a title=""HoverClock"" href=""http://localhost/hvtimg/201601/thbniyjx.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201601/thbniyjx_l.png"" style=""width:180px;height:140px;"" /></a><a title=""javascript元旦倒计时特效"" href=""http://localhost/hvtimg/201512/o9qashmi.gif" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/o9qashmi_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""下雨"" href=""http://localhost/hvtimg/201512/f748s0ko.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/f748s0ko_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""直接说喜欢你!"" href=""http://localhost/hvtimg/201512/vt1tf0xl.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/vt1tf0xl_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""IIS7,IIS7.5 URL重写模块工具"" href=""http://localhost/hvtimg/201512/ew4yb78b.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/ew4yb78b_l.png"" style=""width:180px;height:140px;"" /></a><a title=""山水画"" href=""http://localhost/hvtimg/201512/agagq0or.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/agagq0or_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""刘德华"" href=""http://localhost/hvtimg/201512/r51a22uy.gif" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/r51a22uy_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""IIS为网站设置域名"" href=""http://localhost/hvtimg/201512/69yoeuhf.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/69yoeuhf_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""HoverTreeCMS分成"" href=""http://localhost/hvtimg/201512/jgi94fdf.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201512/jgi94fdf_l.png"" style=""width:180px;height:140px;"" /></a><a title=""范冰冰"" href=""http://localhost/hvtimg/201511/6j9j6tk5.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201511/6j9j6tk5_l.png"" style=""width:180px;height:140px;"" /></a><a title=""周末愉快"" href=""http://localhost/hvtimg/201511/60mj4wsb.gif" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201511/60mj4wsb_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""谢霆锋手机背景图"" href=""http://localhost/hvtimg/201508/cnvkv745.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201508/cnvkv745_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""现代舞舞蹈家玛莎·葛兰姆动画Logo"" href=""http://localhost/hvtimg/201506/ufigfjvn.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201506/ufigfjvn_l.jpg"" style=""width:180px;height:140px;"" /></a><a title=""每次吵架,都希望男票这样解决战斗。。。"" href=""http://localhost/hvtimg/201506/iqoqrhfn.gif" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201506/iqoqrhfn_l.gif"" style=""width:180px;height:140px;"" /></a><a title=""现代舞舞蹈家玛莎·葛兰姆动画Logo"" href=""http://localhost/hvtimg/201506/xlyxp4wg.png" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/hvtimg/201506/xlyxp4wg_l.png"" style=""width:180px;height:140px;"" /></a><a title=""|美女|"" href=""http://localhost/hvtimg/201506/m921jw4n.jpg" rel="external nofollow" rel="external nofollow" "><img src=""http://localhost/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://localhost/hvtimg/201601/p3t2ldyr.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201601/p3t2ldyr_l.png"" style="width:180px;height:140px;" /></a>
<a title="VS2015开发人员命令提示查看PublicKeyToken(公钥标记)" href=""http://localhost/hvtimg/201601/wn0bamxp.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201601/wn0bamxp_l.png"" style="width:180px;height:140px;" /></a>
<a title="消灭僵尸游戏" href=""http://localhost/hvtimg/201601/q47add2k.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201601/q47add2k_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="纯CSS3漂亮的房子不错的天气" href=""http://localhost/hvtimg/201601/lbau8hqb.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201601/lbau8hqb_l.png"" style="width:180px;height:140px;" /></a>
<a title="HoverClock" href=""http://localhost/hvtimg/201601/thbniyjx.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201601/thbniyjx_l.png"" style="width:180px;height:140px;" /></a>
<a title="javascript元旦倒计时特效" href=""http://localhost/hvtimg/201512/o9qashmi.gif" rel="external nofollow" rel="external nofollow" >
<img src=""http://localhost/hvtimg/201512/o9qashmi_l.gif" style="width:180px;height:140px;" /></a>
<a title="下雨" href=""http://localhost/hvtimg/201512/f748s0ko.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/f748s0ko_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="直接说喜欢你!" href=""http://localhost/hvtimg/201512/vt1tf0xl.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/vt1tf0xl_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="IIS7,IIS7.5 URL重写模块工具" href=""http://localhost/hvtimg/201512/ew4yb78b.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/ew4yb78b_l.png"" style="width:180px;height:140px;" /></a>
<a title="山水画" href=""http://localhost/hvtimg/201512/agagq0or.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/agagq0or_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="刘德华" href=""http://localhost/hvtimg/201512/r51a22uy.gif" rel="external nofollow" rel="external nofollow" >
<img src=""http://localhost/hvtimg/201512/r51a22uy_l.gif" style="width:180px;height:140px;" /></a>
<a title="IIS为网站设置域名" href=""http://localhost/hvtimg/201512/69yoeuhf.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/69yoeuhf_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="HoverTreeCMS分成" href=""http://localhost/hvtimg/201512/jgi94fdf.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201512/jgi94fdf_l.png"" style="width:180px;height:140px;" /></a>
<a title="范冰冰" href=""http://localhost/hvtimg/201511/6j9j6tk5.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201511/6j9j6tk5_l.png"" style="width:180px;height:140px;" /></a>
<a title="周末愉快" href=""http://localhost/hvtimg/201511/60mj4wsb.gif" rel="external nofollow" rel="external nofollow" >
<img src=""http://localhost/hvtimg/201511/60mj4wsb_l.gif" style="width:180px;height:140px;" /></a>
<a title="谢霆锋手机背景图" href=""http://localhost/hvtimg/201508/cnvkv745.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201508/cnvkv745_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="现代舞舞蹈家玛莎·葛兰姆动画Logo" href=""http://localhost/hvtimg/201506/ufigfjvn.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201506/ufigfjvn_l.jpg"" style="width:180px;height:140px;" /></a>
<a title="每次吵架,都希望男票这样解决战斗。。。" href=""http://localhost/hvtimg/201506/iqoqrhfn.gif" rel="external nofollow" rel="external nofollow" >
<img src=""http://localhost/hvtimg/201506/iqoqrhfn_l.gif" style="width:180px;height:140px;" /></a>
<a title="现代舞舞蹈家玛莎·葛兰姆动画Logo" href=""http://localhost/hvtimg/201506/xlyxp4wg.png" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201506/xlyxp4wg_l.png"" style="width:180px;height:140px;" /></a>
<a title="|美女|" href=""http://localhost/hvtimg/201506/m921jw4n.jpg" rel="external nofollow" rel="external nofollow" ">
<img src=""http://localhost/hvtimg/201506/m921jw4n_l.jpg"" style="width:180px;height:140px;" /></a>
</div>
*/
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools./regex/javascript
正则表达式在线生成工具:
http://tools./regex/create_reg
更多关于C#相关内容感兴趣的读者可查看本站专题:《WinForm控件用法总结》、《C#窗体操作技巧汇总》、《C#数据结构与算法教程》、《C#常见控件用法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》
希望本文所述对大家C#程序设计有所帮助。
# WinForm
# 正则表达式
# 提取
# 内容
# 使用C# Winform应用程序获取网页源文件的解决方法
# C#基于正则表达式实现获取网页中所有信息的网页抓取类实例
# 使用C#正则表达式获取必应每日图片地址
# C#正则表达式获取下拉菜单(select)的相关属性值
# C#使用正则表达式抓取网站信息示例
# C#通过正则表达式实现提取网页中的图片
# c# 正则表达式对网页进行有效内容抽取
# 常用正则 常用的C#正则表达式
# C#的正则表达式Regex类使用简明教程
# C# 正则表达式经典分类整理集合手册
# C#中的正则表达式 学习资料
# 玛莎
# 程序设计
# 重写
# 喜欢你
# 开发人员
# 倒计时
# 霆锋
# 元旦
# 周末
# 公钥
# 相关内容
# 感兴趣
# 数据结构
# 给大家
# 更多关于
# 所述
# 使用技巧
# 面向对象
# 文本框
相关文章:
台州网站建设制作公司,浙江手机无犯罪记录证明怎么开?
建站之星图片链接生成指南:自助建站与智能设计教程
营销式网站制作方案,销售哪个网站招聘效果最好?
如何高效利用亚马逊云主机搭建企业网站?
如何注册花生壳免费域名并搭建个人网站?
如何访问已购建站主机并解决登录问题?
孙琪峥织梦建站教程如何优化数据库安全?
如何使用Golang安装API文档生成工具_快速生成接口文档
整人网站在线制作软件,整蛊网站退不出去必须要打我是白痴才能出去?
单页制作网站有哪些,朋友给我发了一个单页网站,我应该怎么修改才能把他变成自己的呢,请求高手指点迷津?
Python多线程使用规范_线程安全解析【教程】
专业的网站制作设计是什么,如何制作一个企业网站,建设网站的基本步骤有哪些?
头像制作网站在线制作软件,dw网页背景图像怎么设置?
学校免费自助建站系统:智能生成+拖拽设计+多端适配
网站制作壁纸教程视频,电脑壁纸网站?
建站主机无法访问?如何排查域名与服务器问题
如何用景安虚拟主机手机版绑定域名建站?
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
在线ppt制作网站有哪些,请推荐几个好的课件下载的网站?
定制建站哪家更专业可靠?推荐榜单揭晓
建站之星安装需要哪些步骤及注意事项?
一键网站制作软件,义乌购一件代发流程?
广州网站制作公司哪家好一点,广州欧莱雅百库网络科技有限公司官网?
如何在Windows环境下新建FTP站点并设置权限?
网站制作报价单模板图片,小松挖机官方网站报价?
宠物网站制作html代码,有没有专门介绍宠物如何养的网站啊?
高端建站三要素:定制模板、企业官网与响应式设计优化
如何通过西部数码建站助手快速创建专业网站?
详解jQuery中基本的动画方法
大连网站制作公司哪家好一点,大连买房网站哪个好?
如何在服务器上三步完成建站并提升流量?
如何快速生成橙子建站落地页链接?
建站IDE高效指南:快速搭建+SEO优化+自适应模板全解析
宝塔新建站点为何无法访问?如何排查?
如何在VPS电脑上快速搭建网站?
建站10G流量真的够用吗?如何应对访问高峰?
北京企业网站设计制作公司,北京铁路集团官方网站?
如何通过二级域名建站提升品牌影响力?
如何用美橙互联一键搭建多站合一网站?
如何通过主机屋免费建站教程十分钟搭建网站?
建站主机选购指南:核心配置与性价比推荐解析
网站制作大概多少钱一个,做一个平台网站大概多少钱?
网页制作模板网站推荐,网页设计海报之类的素材哪里好?
电商平台网站制作流程,电商网站如何制作?
北京网站制作的公司有哪些,北京白云观官方网站?
公司门户网站制作公司有哪些,怎样使用wordpress制作一个企业网站?
建站之星价格显示格式升级,你的预算足够吗?
代刷网站制作软件,别人代刷火车票靠谱吗?
宝塔新建站点报错如何解决?
javascript中对象的定义、使用以及对象和原型链操作小结
*请认真填写需求信息,我们会在24小时内与您取得联系。