C# 正则表达式 获取字符的问题

cc小花猫 2013-07-22 03:28:13
C# 正则表达式 获取字符的问题

如何获取到 网址 并循环输出呢?

<ul><li><span>1.</span> <a href='http://s.ianhai.com' target=_blank>s.ianhai.com</a></li><li><span>2.</span> <a href='http://51tttg.com' target=_blank>51tttg.com</a></li><li><span>3.</span> <a href='http://www.ued6.com' target=_blank>www.ued6.com</a></li><li><span> </ul>


我想要输出的内容是:
http://s.ianhai.com
http://51tttg.com
http://www.ued6.com
...全文
80 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cc小花猫 2013-07-22
  • 打赏
  • 举报
回复
引用 4 楼 q107770540 的回复:
string e="<ul><li><span>1.</span> <a href='http://s.ianhai.com' target=_blank>s.ianhai.com</a></li><li><span>2.</span> <a href='http://51tttg.com' target=_blank>51tttg.com</a></li><li><span>3.</span> <a href='http://www.ued6.com' target=_blank>www.ued6.com</a></li><li><span> </ul> ";

	string f = @"(?i)(?<=<a\b[^>]*?href=(['""]))[^<>]+(?=\1)"; 
	foreach(Match m in Regex.Matches(e,f))
			Console.WriteLine(m.Value);
给力 谢谢~~~~~~~~~~~~~
q107770540 2013-07-22
  • 打赏
  • 举报
回复
string e="<ul><li><span>1.</span> <a href='http://s.ianhai.com' target=_blank>s.ianhai.com</a></li><li><span>2.</span> <a href='http://51tttg.com' target=_blank>51tttg.com</a></li><li><span>3.</span> <a href='http://www.ued6.com' target=_blank>www.ued6.com</a></li><li><span> </ul> ";

	string f = @"(?i)(?<=<a\b[^>]*?href=(['""]))[^<>]+(?=\1)"; 
	foreach(Match m in Regex.Matches(e,f))
			Console.WriteLine(m.Value);
渴望蜕变 2013-07-22
  • 打赏
  • 举报
回复
MatchCollection mc = Regex.Matches(table, @"(?i)(?<=<a\b[^>]*?href=(['""]))[^<>]+(?=\1)")", RegexOptions.IgnoreCase); foreach (Match m in mc) {} 这样等到所有匹配的
cc小花猫 2013-07-22
  • 打赏
  • 举报
回复
引用 1 楼 q107770540 的回复:
(?i)(?<=<a\b[^>]*?href=(['"]))[^<>]+(?=\1)
string e="<ul><li><span>1.</span> <a href='http://s.ianhai.com' target=_blank>s.ianhai.com</a></li><li><span>2.</span> <a href='http://51tttg.com' target=_blank>51tttg.com</a></li><li><span>3.</span> <a href='http://www.ued6.com' target=_blank>www.ued6.com</a></li><li><span> </ul> "; string f = @"(?i)(?<=<a\b[^>]*?href=(['""]))[^<>]+(?=\1)";(这样对吗?) for(i) string g = Regex.Match(e, f).Value.ToString(); 然后如何用for循环输出 谢谢
q107770540 2013-07-22
  • 打赏
  • 举报
回复
(?i)(?<=<a\b[^>]*?href=(['"]))[^<>]+(?=\1)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧