正则问题
对于下面的文本
<div class="remark"><span id="jj"><a href="http://sms.cnfol.com/wap/index.shtml" target="_blank">手机免费访问</a></span> <a href="http://www.cnfol.com" target="_blank">www.cnfol.com</a> 2010年06月02日 10:26 证券时报 <a href="http://sms.cnfol.com/wap/index.shtml"></a></div>
我要得到时间和来源,而且只能使用声明正则表达式的方式解决
比如
string newsTimePattern = "...";
string sourcePattern = "...";
因为基类当中已经有固定的方法处理,如
news.NewsTime = GetNewsTime(GetValue(html, newsTimePattern));
news.Source = GetSource(GetValue(html, sourcePattern));
protected string GetValue(string text, string pattern)
{
string value = string.Empty;
Regex regex = new Regex(pattern);
Match match = regex.Match(text);
if (match.Success)
{
value = match.Value.Trim();
}
return value;
}
所以我只需要把文本和验证表达式传进来就好
目前我写的正则如下
string newsTimePattern = @"(?<=手机免费访问</a></span>\s*<a\s*href=""http://www.cnfol.com""\s*target=""_blank"">www.cnfol.com</a>)[\s\S]*?(?=<a)";
但这样得到的内容是 2010年06月02日 10:26 证券时报
请问如何用两个正则分别得到"时间"和"来源",再次强调,正则写的丑陋不要紧,要紧的是把字符串传进去就要出结果,在这段代码中时间和来源是变量,其他格式不变。