正则表达式复习 (?<=) (?=)
1.首先值得一说的是"<" 和">" 不是元字符 "."是元字符 ,连接字符"-",即使在字符组内部也不一定就是元字符,如果连接字符出现在字符组的开头,它表示的就是一个普通的字符,而不是一个范围如[a-zA-z0-9]里的连接字符"-",代表的就是一个范围小写字符a到z或大写字符A到Z或数字0到9,
同样的"?"和"."(问号和点通常被认为是元字符)但在字符组内部[a-zA-Z_!.]的特殊字符(元字符)就只有两个连接符("-")。
下面的图解中,第三组括号的内容被取了别名tdCell
private string getHtml()
{
try
{
date = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 09:30:00";
WebClient wc = new WebClient();
//string reg = "<td(\\s+)?width=\"15%\"(\\s+)?align=\"center\"><a(\\s+)?href=\"#\".+<font(\\s+)?color=blue>(?<type>.+)(\\s+)?</font>.+(\\s+)?<td(\\s+)?width=\"35%\"(\\s+)?align=\"center\">(?<values>.+)(\\s+)?</td>(\\s+)?<td(\\s+)?width=\"10%\"(\\s+)?align=\"right\"><img(\\s+)?src=\"/shibor/web/html/images/newimages/(?<image>.+)\"(\\s+)?width=\"11\"(\\s+)?height=\"11\"(\\s+)?/>.+(\\s+)<td(\\s+)?width=\"25%\"(\\s+)?align=\"left\">(?<BP>.+)(\\s+)?</td>";
using (Stream stream = wc.OpenRead("http://www.shibor.org/shibor/ShiborTendaysShow.do"))
{
using (StreamReader sr = new StreamReader(stream, Encoding.Default))
{
string content = sr.ReadToEnd();
//单行模式匹配
//让.可以匹配到\n
string clas;
//string patern = @"(?<=<table id=""result"" cellpadding=""0"" class=""shiborquxian2"">)([\s\S]*?)(?=</table>)";
string patern = @"(?<=<table (.*)?class=""shiborquxian2""[^>]*?>)([\s\S]*?)(?=</table>)";
MatchCollection matches = Regex.Matches(content, patern);
string trs = string.Empty;
foreach (Match match in matches)
{
trs = match.Groups[0].Value;
break;
}
string trPatern = @"(?<=<tr(.*)?[^>]*?>)([\s\S]*?)(?=</tr>)";
MatchCollection trMatchCollection = Regex.Matches(trs, trPatern);
List<string> trList = new List<string>();
List<string> CurrentTrList = new List<string>();
for (int j = 0; j < trMatchCollection.Count; j++)
{
Match match = trMatchCollection[j];
string tr = string.Empty;
tr = match.Groups[0].Value;
CurrentTrList.Add(tr);
if (j == 1)
{
trList.Add(tr);
break;
}
}
//
string tdPatern = @"(?<=(<td[^>]*?>))(?<tdCell>[\s\S]*?)(?=</td>)";
MatchCollection tdMatchCollection = Regex.Matches(trList[0], tdPatern);
MatchCollection CurrenttdMatchCollection = Regex.Matches(CurrentTrList[0], tdPatern);
string td = string.Empty;
List<string> tdlList = new List<string>();
List<string> CurrenttdlList = new List<string>();
foreach (Match match in CurrenttdMatchCollection)
{
td = match.Groups["tdCell"].Value;
CurrenttdlList.Add(td);
}
foreach (Match match in tdMatchCollection)
{
td = match.Groups["tdCell"].Value;
tdlList.Add(td);
}
infoTitleW = CurrenttdlList[0];
List<string> termList = new List<string>()
{
"O/N","1W","2W","1M","2M","3M","6M","9M","1Y"
};
MKT += @"
<ul id='xianc' class='pricing_table'>
<li class='price_block'>
<h5 style='color: #ffffff;'>期限</h5>
<ul class='features'>
<li>O/N</li>
<li>1W</li>
<li>2W</li>
<li>1M</li>
<li>3M</li>
<li>6M</li>
<li>9M</li>
<li>1Y</li>
</ul>
</li>
";
MKT += @" <li class='price_block'>
<h5 style='color:#ffffff'>Shibor(%)</h5>
<ul class='features'>";
for (int i = 1; i < tdlList.Count; i++)
{
decimal prior = decimal.Parse(tdlList[i].ToString());
decimal curr = decimal.Parse(CurrenttdlList[i].ToString());
decimal change = (curr - prior) * 100;
MKT += string.Format("<li>{0}</li>", curr);
}
MKT += "</ul></li>";
MKT += @" <li class='price_block'>
<h5 style='color:#ffffff'>变化值(BP)</h5>
<ul class='features'>";
for (int i = 1; i < tdlList.Count; i++)
{
decimal prior = decimal.Parse(tdlList[i].ToString());
decimal curr = decimal.Parse(CurrenttdlList[i].ToString());
decimal change = (curr - prior) * 100;
MKT += string.Format("<li>{0}</li>", change);
}
MKT += "</ul></li>";
MKT += @" <li class='price_block'>
<h5 style='color:#ffffff'>涨跌(BP)</h5>
<ul class='features'>";
for (int i = 1; i < tdlList.Count; i++)
{
decimal prior = decimal.Parse(tdlList[i].ToString());
decimal curr = decimal.Parse(CurrenttdlList[i].ToString());
decimal change = (curr - prior) * 100;
MKT += string.Format("<li> {0} </li>", change >= 0 ? "<img height=7 src='/images/upicon.gif'>" : "<img height=7 src='/images/downicon.gif'>");
}
MKT += "</ul></li></ul>";
}
}
}
catch (Exception ex)
{
MKT = "部分内容加载失败因为:" + ex.Message + "<br/><br/>请点击 <a href='#' id='relaod' style='color:blue;'>重新加载</a>";
//Response.Write("部分内容加载失败因为:" + ex.Message + "\n请尝试重新刷新页面");
//Response.End();
// throw new Exception("部分内容加载失败因为:"+ex.Message+"\n请尝试重新刷新页面");
}
return MKT;
}
protec
正则表达式复习 (?<=) (?=)的更多相关文章
- python re 正则表达式复习
正则表达式是一种小巧的独立语言,用于字符串的匹配 一.元字符 1.. 匹配除换行符外的任意字符 2.^ 匹配字符串开头 3.$ 匹配字符串末尾 4.* 匹配前一字符n次 5.+ 匹配前一字符1-n次 ...
- java 正则表达式 复习
正则表达式在日常开发中会经常的接触到,学会了正则可以更有效的对字符进行验证.拆分.替换.判断字符串是否合法等操作... 常用语法: 字符的取值范围 1.[abc] : 表示可能是a,可能是b,也可能是 ...
- C# 正则表达式 -- 复习
符号解释: \ 特殊的字符,转义 ^ 匹配输入的字符串的开始位置 $ 匹配输入的字符串的结束位置 * 匹配0次或多次,等价于{0,} + 匹配1次或多次,等价于{1,} ? 匹配0次或1次,等价于{0 ...
- C#复习正则表达式
由于前段时间为了写工具学的太J8粗糙 加上最近一段时间太浮躁 所以静下心来复习 一遍以前学的很弱的一些地方 1 委托 public delegate double weituo(double a, d ...
- linux 下 Emacs dired 模式 隐藏 dot file ".filename" 文件
有时候 emacs 下调用 C-x dired 是挺方便的一个事,但是一堆的点文件(linux下以"."为前缀的文件,即隐藏文件)让人目不暇接,打算隐藏之. 参考如下: 最主要的是 ...
- Java爬虫初体验
年关将近,工作上该完成的都差不多了,上午闲着就接触学习了一下爬虫,抽空还把正则表达式复习了,Java的Regex和JS上还是有区别的,JS上的"\w"Java得写成"\\ ...
- 【JS复习笔记】05 正则表达式
好吧,正则表达式,我从来没记过.以前要用的时候都是网上Copy一下的. 这里还是扯一下吧,以后要是有要用到的正则表达式那么就收集到这个帖子里.(尽管我认为不会,因为我根本就不是一个专业的前端,我只是来 ...
- Web服务器-正则表达式-整理+复习(3.1.1)
@ 目录 1.常用api 2.例子 3.正则表达式模式 关于作者 参考文章 1.常用api re.match(pattern, string, flags=0) pattern 匹配的正则表达式 st ...
- [Java基础复习] -- x. 正则表达式的使用
序号待定, 先用x占位表示 理论知识待完善, 先贴上代码 import java.util.regex.Matcher; import java.util.regex.Pattern; import ...
随机推荐
- 【java规则引擎】一个基于drools规则引擎实现的数学计算例子
最近在研究JBPM工作流引擎,发现JBPM是基于Drools的,官方文档查看得知Drools是一款规则引擎.兴趣之下,仔细了解了下 Drools,Drools作为JBoss出品的一款开源推理和规则引擎 ...
- LG3195 [HNOI2008]玩具装箱TOY
题意 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为\(1\cdots N\) ...
- nmon的使用
Linux性能评测工具之一:nmon篇 分类: 敏捷实践2010-06-08 11:27 7458人阅读 评论(0) 收藏 举报 工具linuxfilesystemsaixx86excel 目录( ...
- Tornado服务端基本的配置文件(Python)
web_set = { # -------一般设置-------- 'debug': True, 'port': 8836, 'autoreload': True, 'ui_modules': {}, ...
- C#网络编程(订立协议和发送文件) - Part.4
文件传输 前面两篇文章所使用的范例都是传输字符串,有的时候我们可能会想在服务端和客户端之间传递文件.比如,考虑这样一种情况,假如客户端显示了一个菜单,当我们输入S1.S2或S3(S为Send缩写)时, ...
- 平台调用之如何利用VS2013 C#调试C++DLL库
对于托管代码调用非托管DLL文件,已经是非常普遍的事情,下面写一下如何通过托管代码(C#)像调试托管代码一样调试DLL中的代码. 注意:(1)[dll工程和调用dll的exe工程需要在同一个解决方案中 ...
- 【转】Jmeter 代理服务器录制脚本
因为Badboy只支持IE浏览器,现在又不得不到到fireFox上录制脚本才能完成,再次重温下Jmeter自带的Http代理服务器,当然比起badboy,它稍稍麻烦点. 1 配置很简单 工作台--& ...
- HTML简历
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 杂项-WiFi:JotSpot
ylbtech-杂项-WiFi:JotSpot JotSpot公司成立于2003年,由曾经创建了搜索引擎Excite的Joe Kraus一手创建,曾获得了来自Mayfield和RedPoint 两家风 ...
- HEALTH_WARN too few PGs per OSD (21 < min 30)解决方法
标签(空格分隔): ceph,ceph运维,pg 集群环境: [root@node3 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 ...