网页中有
<a href="a.htm"><img src=a.jpg></a>其他内容<a href="a.htm">这是a</a>其他内容
<a href="b.htm"><img src=b.jpg></a>其他内容<a href="b.htm">这是b</a>其他内容
<a href="c.htm"><img src=c.jpg></a>其他内容<a href="c.htm">这是c</a>其他内容想提供网页的链接"a.htm","b.htm","c.htm",不知道如何写正则表达式呢。
因为"a.htm","b.htm","c.htm"总是有两个,是会重复的,谢谢了。
<a href="a.htm"><img src=a.jpg></a>其他内容<a href="a.htm">这是a</a>其他内容
<a href="b.htm"><img src=b.jpg></a>其他内容<a href="b.htm">这是b</a>其他内容
<a href="c.htm"><img src=c.jpg></a>其他内容<a href="c.htm">这是c</a>其他内容想提供网页的链接"a.htm","b.htm","c.htm",不知道如何写正则表达式呢。
因为"a.htm","b.htm","c.htm"总是有两个,是会重复的,谢谢了。
解决方案 »
- C#多个线程能同时访问一个方法吗?
- 关于实现接口的类中实现自己的方法调用的问题
- API问题?
- 唉,如何给我的工程文件夹改名啊?C#的~~~~~~~~
- web如何实现保存提示框??
- "scrollbar-face-color:#6699cc;"这个代码在VS2008的样式表里怎么不支持呀??
- 如何用C#為指定IE網頁傳遞類似鍵盤輸入的效果(用WinForm程序實現,不用ASP程序),謝謝……………
- 怎么样能使当前的年,月,日的值,分别负给3个String的变量!!
- 无法将类型为“System.String”的对象强制转换为类型“System.Collections.ArrayList”。
- 利用C#来实现向一远程主机传输图片怎么办啊?
- 关于输入法超级难的问题,高手进来帮忙
- 传统C/S结构模式(WinForm)的Cache的数据同步问题
MatchCollection urls = Regex.Matches(p_Input, p_Pattern, RegexOptions.IgnoreCase);
Hashtable arr = new Hashtable();
foreach(Match url in urls){
try{
arr.Add(url.ToString());
}catch{}
}
foreach(Match url in urls){
try{
arr.Add(url.ToString(),url.ToString());
}catch{}
}
我想匹配<a href="*">,得到*的内容,谢谢。
public class Test
{
public static void Main()
{
string html = "your html here";
StringCollection urls = GetUrlsInHtml(html); foreach(string url in urls )
{
Console.WriteLine(url);
}
}
public static StringCollection GetUrlsInHtml(string html)
{
string pattern = @"href=""(?<url>\w+\.htm)""";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(html); StringCollection urls = new StringCollection(); foreach (Match match in matches)
{
string url = match.Groups["url"].Value;
if (!urls.Contains(url))
{
urls.Add(url);
}
} return urls;
}
}