温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在WinForm中利用正则表达式提取内容

发布时间:2021-04-09 18:01:24 来源:亿速云 阅读:126 作者:Leah 栏目:编程语言

怎么在WinForm中利用正则表达式提取内容?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

代码如下:

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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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"" 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""  /></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""  /></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""  /></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""  /></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""  /></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"  /></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""  /></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""  /></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""  /></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""  /></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"  /></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""  /></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""  /></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""  /></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"  /></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""  /></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""  /></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"  /></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""  /></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""  /></a>
</div>
*/

关于怎么在WinForm中利用正则表达式提取内容问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI