"(<script(.*?)>)(.|\n)*?(</script>)";
上述正则表达式可以匹配所有<script></script>中的内容
<script type="text/javascript">
owner = '';
us = '';
downloadlink = '/fs-223157/dl/?file=dsVltQ5twffevgFLbXYbELSU9vXx9zOa7Puf9qxcqib1CNeKddHUZkKYjgRLnGWrJPwoReZqnDTlhXDmx8VVuw&token=2S61BYR3q=IUF-Ow_=NrHd';
</script>
如何改造这个正则表达式,直接匹配出downloadlink属性的值
没理解错的话,使用正向肯定/反向否定预查可以实现你要的效果
正则: (?<=<script(.*?)>(.|\n)*?downloadlink = ').*?(?=';\n?</script>)
在js中确实可以,但我这个是需要在C#后端去匹配,这个好像匹配不了0.0
@笑叹、: 我这边测试可以的
贴个测试代码
using System.Text.RegularExpressions;
Console.WriteLine(
new Regex("(?<=<script(.*?)>(.|\n)*?downloadlink = ').*?(?=';\n?</script>)")
.Match(File.ReadAllText("text.txt")).Value);
@Laggage: 需匹配文本:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "//www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:00 GMT" />
<title></title>
<link type="text/css" rel="stylesheet" href="//mimg.127.net/xm/all/fs/style/css/coremail-style-v2.css"/>
<link type="text/css" rel="stylesheet" href="//mimg.127.net/xm/all/fs/style/css/base/reset.css" />
<style type="text/css">
.dot{font-family:simsun;}
</style>
</head>
<body id="page-163-com">
<div class="header clearfix">
<h1 class="logo">
<a href="//mail.163.com/" target="_blank"><img src="//mimg.127.net/logo/163logo.gif" width="136px" height="32px" /></a>
</h1>
<div id="usMsg" style="display:none;" class="wel"><strong></strong> </div>
<div class="ext">
<a target="_blank" href="//zhidao.mail.163.com/zhidao/newsugg.jsp#%E9%99%84%E4%BB%B6"></a>
<span> | </span>
<a target="_blank" href="//help.163.com/10/0106/15/5SBUJ7RV00753VB8.html"></a>
<span> | </span>
<a target="_blank" onclick="location.href=location.href.replace('&language=zh','').replace('&language=en','')+'&language=en'">English</a>
</div>
</div>
<div class="content">
<div id="mbDiv" class="login-mbDiv" style="display:none;"> </div>
<div id="loginDiv" style="display:none;" class="login-iframe"> </div>
<div id="expiredTime" class="msg msg-err" style="display:none;">
</div>
<div class="area clearfix">
<table class="table-main">
<tr>
<div style="border-right:solid 1px #ccc;">
<td class="wd1">
<div class="part part-main">
<h2 class="title">
�������أ�
</h2>
<div class="filename">
<div class="ico ico-file"><img src="//mimg.127.net/xm/all/fj/ico-bfile-7.gif" /></div>
<h3 class="name ne-bwd">sqldeveloper-19.2.1.247.2212-x64.zip</h3>
</div>
<div class="fileinfo">
<div>�ļ���С��<span>490.17M</span></div>
<div>����ʱ�䣺<span>2022-03-05 16:30:53</span></div>
<div>ʣ����Чʱ�䣺<span id="remainingTime">������...</span></div>
</div>
<!--div class="code">
<label class="lb">��������֤�룺</label>
<input id="captcha" class="ipt-t" type="text" />
<img id="captchaIMG" alt="��֤��" />
<a id="changeCaptcha">�����������һ��</a>
<span id="captchaMsg" class="tips tips-err">���ȵ�¼���ȡ��֤��</span>
</div>
<div id="errmsg-div" class="msg msg-alert" style="display:none;">
����Ҫ�ȵ�¼�������ش���<a id="download-b" hidefocus="hidefocus" href="#">������¼</a>
</div-->
<div class="button">
<a id="download-a" class="ipt-b btn btn-std" style="color:black;display:inline-block;" hidefocus="hidefocus" target="_self">��ʼ����</a>
<a class="member-ad" href="https://v.mail.163.com/?utm_source=download_speed" target="_blank">��ͨ��Ա�����ܼ���������Ȩ</a>
</div>
</div>
<div id="enter-report" class="report">ע���������Դ���������Ϲ��ҷ��ɵ�������ݻ���Ϣ����<a style="text-decoration:underline;cursor:pointer;" hidefocus="hidefocus" id="report">������оٱ�<img id="rp-img" src="../style/images/down.gif" /></a></div>
<div id="success-report" class="bgp05 report-success" style="display:none">�ٱ��ɹ���л��Թ�����г��ᣬ�������������������Ĺ��ף�</div>
</div>
</td>
<td class="wd2">
<div class="iblock part part-sec">
<div class="intro">
<h1 class="fs14 fc02"
style="margin-bottom:16px;">���������ʦ������<span class="fw01 fc06">�������</span>��</h1>
<p class="lh-26"><strong>1.</strong> ���ʼ�ʵʱ���ѣ�֧����ʱ�������շ���</p>
<p class="lh-26"><strong>2.</strong> ֧���ֻ�����ת���������أ�������ʡ������</p>
<p class="lh-26"><strong>3.</strong> ǩ�������ʦ�Ƹ������������15G�����и������</p>
<p class="lh-26"><strong>4.</strong> �����ʦ�������ָ������ᡣ</p>
<p style="padding-top:10px;"><a style="margin:0 20px;" class="fw01" href="//mail.163.com/dashi/activity/gift/index.jsp?from=fj" target="_blank">����ǩ��</a><a href="//mail.163.com/client/dl.html?from=mail13" target="_blank" class="dot">�˽����>></a></p>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="rp-form" style="display:none;" id="reportForm">
<h1 class="fc03 rp-title">�ٱ���ҳ��Դ����ѡ��ٱ�ԭ��:</h1>
<table class="rp-table" border="0" cellspacing="0" cellpadding="0">
<tr class="fc03"><td class="radio-td"><input onclick="Download.__onChange(0)" id="radio0" name="radio" type="radio" value="����ɫ�鱩������" /></td><td>����ɫ�鱩������</td></tr>
<tr class="fc03"><td class="radio-td"><input onclick="Download.__onChange(1)" id="radio1" name="radio" type="radio" value="���ǹ��" /></td><td>���ǹ��</td></tr>
<tr class="fc03"><td class="radio-td"><input onclick="Download.__onChange(2)" id="radio2" name="radio" type="radio" value="���������" /></td><td>���������</td></tr>
<tr class="fc03"><td class="radio-td"><input onclick="Download.__onChange(3)" id="radio3" name="radio" type="radio" value="����" /></td><td>����</td></tr>
<tr class="fc03"><td class="radio-td"><input onclick="Download.__onChange(4)" id="radio4" name="radio" type="radio" value="����" /></td><td>����<input id="other" disabled="disabled" style="margin-left:5px;" type="text" /></td></tr>
</table>
<div style="margin-top:15px;margin-left:10px;"><input style="overflow:visible;" onclick="Download.__onReport();" type="button" value="�ٱ���Դ" /><input id="cnl-btn" style="margin-left:10px;overflow:visible;" onclick="Download.__onReportHide();" type="button" value="ȡ��" /></div>
</div>
</td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
<div class="footer">
<div><a target="_blank" href="//corp.163.com/">About NetEase</a><span>|</span>
<a target="_blank" href="//gb.corp.163.com/gb/about/overview.html"></a><span>|</span>
<a target="_blank" href="//gb.corp.163.com/gb/contactus.html"></a><span>|</span>
<a target="_blank" href="//corp.163.com/gb/job/job.html">��Ƹ��Ϣ</a><span>|</span>
<a target="_blank" href="//help.163.com/">�ͻ�����</a><span>|</span>
<a target="_blank" href="//gb.corp.163.com/gb/legal.html">��ط���</a><span>|</span>
<a target="_blank" href="//emarketing.biz.163.com/">����Ӫ��</a>
</div>
<div class="fc02">Copyright © 1997-<script src="https://mimg.127.net/copyright/year.js"></script> ����˾��Ȩ����</div>
</div>
</div>
</body>
<script type="text/javascript" src="//mimg.127.net/xm/all/fs/js/gen/lib.js"></script>
<script type="text/javascript">
owner = '';
us = '';
downloadlink = '/fs-223157/dl/?file=dsVltQ5twffevgFLbXYbELSU9vXx9zOa7Puf9qxcqib1CNeKddHUZkKYjgRLnGWrJPwoReZqnDTlhXDmx8VVuw&token=2S61BYR3q=IUF-Ow_=NrHd';
file = 'dsVltQ5twffevgFLbXYbELSU9vXx9zOa7Puf9qxcqib1CNeKddHUZkKYjgRLnGWrJPwoReZqnDTlhXDmx8VVuw';
product = '163mail';
lExpiredTime = '1646469053622';
uuid = '57298a01-22ac-4c5c-a7c4-16446024bb40';
error = '';
downloadCountLimit = '';
sExpiredTime = '2022-03-05 16:30:53';
sCurrentTime = 1645411134170;
</script>
<script type="text/javascript" src="//mimg.127.net/xm/all/fs/js/pro/download/mail-download-v2.js"></script>
</html>
后台源码:
Regex reg = new Regex(@"(?<=<script(.*?)>(.|\n)*?downloadlink = ').*?(?=';\n?</script>)");
MatchCollection match = reg.Matches(strHTML);
@笑叹、:
正则换一下,换成(?<=<script(.*?)>(.|\n)*?downloadlink = ').*?(?='(.|\n)*?</script>)
@Laggage: 可以了,跪谢大佬