读书人

关于 quot;正则quot; 的小疑点。求解答

发布时间: 2013-08-10 21:14:06 作者: rapoo

关于 "正则" 的小问题。求解答


[解决办法]
<CODE>(?<code>[^<>]+)</CODE>.*<DES>(?<des>[\s\S]*?)</DES>


[解决办法]

public static string[] GetHtmlImageUrlList(string sHtmlText)
{
string pattern = "(?is)<CODE>(?<code>.*?)</CODE>.*?<DES>(?<des>.*?)</DES>";

Regex regImg = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = regImg.Matches(sHtmlText);
string[] result = new string[2];
foreach (Match match in matches)
{
result[0] = match.Groups["code"].Value.ToString();
result[1] = match.Groups["des"].Value.ToString();
}
return result;
}

读书人网 >C#

热点推荐