正则表达式复习 (?<=) (?=)
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 ...
随机推荐
- 大容量txt数据导入SQL Server助攻记
小伙伴们有个数据竞赛,提供的数据是944MB大小的TXT数据文档,导入SQL遇到一些麻烦.于是帮着解决,顺便也熟练了SQL Server的一些操作----- 打开如此大的txt需要的时间很长,而且不全 ...
- 洛谷P1979 华容道
神の契约 题目大意:自己看去... 题解:做了一下午...本蒟蒻立志要写全网最详细的题解.╭(╯^╰)╮ begin.... 暴力70分.可以让空格子到处乱走,只要某个状态的指定格子到目标格子,那么此 ...
- 当 PHP 遇上 MongoDB
FROM:http://www.cstor.cn/textdetail_7995.html 之前笔者出了一篇文章是教大家在 Linux 下安装 MongoDB,并且透过 Mongo Client 操作 ...
- CSS冷门但有用的知识整合
1. 滚动条样式设置 The ::-webkit-scrollbar CSS pseudo-element(伪元素) affects the style of the scrollbar of an ...
- Linux 应用层open调用驱动层open过程
内核版本:3.0.8 open.close.read.write.ioctl等等都是类似. ====================================================== ...
- 搭建Dynamic Web Project(动态web项目)的springmvc工程1
本文转载自:http://blog.csdn.net/typa01_kk/article/details/45902955 此篇创建Dynamic Web Projec工程(动态web项目),下一篇, ...
- linux输入子系统之按键驱动
上一节中,我们讲解了Linux input子系统的框架,到内核源码里详细分析了输入子系统的分离分层的框架等. 上一节文章链接:http://blog.csdn.net/lwj103862095/ar ...
- Linux - 归档和压缩
归档 归档就是将多个文件或目录合并成一个文件 归档的目的就是方便备份.还原及文件的传输操作 tar 命令:将多个文件或目录归档到一个文件中,可以根据需要只还原归档文件中的某些指定的文件 c:创建,v: ...
- Wireshark捕获非加密的数据包
启动监听模式 root@sch01ar:~# airmon-ng start wlan0 启动Wireshark工具 root@sch01ar:~# wireshark 选择接口,这里选择wlan0m ...
- 虚拟机之 LNMP
LNMP就是Linux nginx mysql php 一.mysql 下载安装mysql转至 LAMP (点击“LAMP”即可跳转) 也可以从快照跳转至mysql安装ok 二.php 下载同上, 1 ...