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>&nbsp{0}&nbsp</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/>请点击&nbsp;&nbsp;&nbsp;<a href='#' id='relaod' style='color:blue;'>重新加载</a>";
//Response.Write("部分内容加载失败因为:" + ex.Message + "\n请尝试重新刷新页面");
//Response.End();
// throw new Exception("部分内容加载失败因为:"+ex.Message+"\n请尝试重新刷新页面");
}
return MKT;
}
protec

正则表达式复习 (?<=) (?=)的更多相关文章

  1. python re 正则表达式复习

    正则表达式是一种小巧的独立语言,用于字符串的匹配 一.元字符 1.. 匹配除换行符外的任意字符 2.^ 匹配字符串开头 3.$ 匹配字符串末尾 4.* 匹配前一字符n次 5.+ 匹配前一字符1-n次 ...

  2. java 正则表达式 复习

    正则表达式在日常开发中会经常的接触到,学会了正则可以更有效的对字符进行验证.拆分.替换.判断字符串是否合法等操作... 常用语法: 字符的取值范围 1.[abc] : 表示可能是a,可能是b,也可能是 ...

  3. C# 正则表达式 -- 复习

    符号解释: \ 特殊的字符,转义 ^ 匹配输入的字符串的开始位置 $ 匹配输入的字符串的结束位置 * 匹配0次或多次,等价于{0,} + 匹配1次或多次,等价于{1,} ? 匹配0次或1次,等价于{0 ...

  4. C#复习正则表达式

    由于前段时间为了写工具学的太J8粗糙 加上最近一段时间太浮躁 所以静下心来复习 一遍以前学的很弱的一些地方 1 委托 public delegate double weituo(double a, d ...

  5. linux 下 Emacs dired 模式 隐藏 dot file ".filename" 文件

    有时候 emacs 下调用 C-x dired 是挺方便的一个事,但是一堆的点文件(linux下以"."为前缀的文件,即隐藏文件)让人目不暇接,打算隐藏之. 参考如下: 最主要的是 ...

  6. Java爬虫初体验

    年关将近,工作上该完成的都差不多了,上午闲着就接触学习了一下爬虫,抽空还把正则表达式复习了,Java的Regex和JS上还是有区别的,JS上的"\w"Java得写成"\\ ...

  7. 【JS复习笔记】05 正则表达式

    好吧,正则表达式,我从来没记过.以前要用的时候都是网上Copy一下的. 这里还是扯一下吧,以后要是有要用到的正则表达式那么就收集到这个帖子里.(尽管我认为不会,因为我根本就不是一个专业的前端,我只是来 ...

  8. Web服务器-正则表达式-整理+复习(3.1.1)

    @ 目录 1.常用api 2.例子 3.正则表达式模式 关于作者 参考文章 1.常用api re.match(pattern, string, flags=0) pattern 匹配的正则表达式 st ...

  9. [Java基础复习] -- x. 正则表达式的使用

    序号待定, 先用x占位表示 理论知识待完善, 先贴上代码 import java.util.regex.Matcher; import java.util.regex.Pattern; import ...

随机推荐

  1. ACM学习历程—TopCoder SRM691 Div2

    这是我的第一次打TC,感觉打的一般般吧.不过TC的题目确实挺有意思的. 由于是用客户端打的,所以就不发题目地址了. 300分的题: 这题大意是有一段序列只包含+和数字0~9. 一段序列的操作是,从头扫 ...

  2. RMAN 增量备份 脚本

    ################################################################## ##    rman_backup.sh              ...

  3. 15.Selenium+Python滑动解锁小案例

    1.代码实现 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChai ...

  4. 遍历listmap 遍历map

    package excel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import j ...

  5. C# byte数组转成Bitmap对象

    方法一: /// <summary> /// 将数组转换成彩色图片 /// </summary> /// <param name="rawValues" ...

  6. Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

    python3.6.3  我在处理爬虫时候使用BeautifulSoup中遇到报错 “ bs4.FeatureNotFound: Couldn't find a tree builder with t ...

  7. Spring Cloud Eureka 注册,发布,调用服务

    Spring Cloud为服务治理做了一层抽象接口,所以在Spring Cloud应用中可以支持多种不同的服务治理框架,如Netflix Eureka.Consul和Zookeeper.在Spring ...

  8. java代码反转toCharAT()的用法

    总结:反转注意for循环里面的变化 package clientFrame; //字符串反转 public class we { public static void main(String[] ar ...

  9. pt工具之pt-archiver

    # tar -zxvf percona-toolkit-2.2.17.tar.gz# yum -y install perl perl-IO-Socket-SSL perl-DBD-MySQL per ...

  10. Java学习之App开发公司手机端设想

    背景:最近在学JAVA,看到JAVA做各种APP,而公司软件主要是做家居设计,使用者多是设计师和家具门店,很难让大部分非专业人士接触到我们的产品,由于设计复杂且占用资源较多不太可能用APP实现网站设计 ...