日期:2014-05-18  浏览次数:20402 次

正则取值
我只取链接为 <a   href=http://www.xxx.com/yyy.aspx?zzz=value> text </a> 中的text值.其中xxx,yyy,zzz是定值,value不定(可以为任意字符且长度不定).试问此正则该如何写,请各位帮个忙.

------解决方案--------------------
try

string yourStr = ..............;
string result = " ";
Match m = Regex.Match(yourStr, @ " <a\s+href=http://www\.xxx\.com/yyy\.aspx\?zzz=[^> ]*> (? <text> [^ <]*) </a> ", RegexOptions.IgnoreCase);
if (m.Success)
result = m.Groups[ "text "].Value;

------解决方案--------------------
string test = @ " <a href=http://www.xxx.com/yyy.aspx?zzz=value> text </a> ";
Regex reg = new Regex(@ "\ <.*\> (? <value> [\s\S]*)\ <\/a\> ");
Match mr = reg.Match(test);
string s = string.Empty;
if (mr.Success)
{
s = mr.Groups[ "value "].Value;
}

---------------------------------------------
EMail:bdbox@163.com 请给我一个与您交流的机会!