c#正则匹配

_小黑_ 2012-12-20 09:21:20

<A class="W_f14 S_func1" href="http://weibo.com/u/1950836865" target=_blank usercard="id=1950836865">公益魏豪</A> <SPAN class=addr><EM class="W_ico12 male"></EM>辽宁 大连 </SPAN>

如何获取 usercard="id=1950836865中1950866865的值和”公益富豪“的值呢
求高手解答谢啦
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
_小黑_ 2012-12-20
  • 打赏
  • 举报
回复
引用 8 楼 hjywyj 的回复:
引用 7 楼 l397870376 的回复: 引用 1 楼 hjywyj 的回复:string pattern=@"(?i)<a[^>]*?href=[""']http://weibo\.com/u/(\d+)[""'][^>]*>([^<]*)</a>"; 高手你的这个是把,字符串给匹配下来了,里面的值没取到啊,谢谢你啦,在帮我一下呗 Group[1]是1950866865 Group[……
高手,你怎么学的正则啊,这么厉害,有什么诀窍没
  • 打赏
  • 举报
回复
引用 7 楼 l397870376 的回复:
引用 1 楼 hjywyj 的回复:string pattern=@"(?i)<a[^>]*?href=[""']http://weibo\.com/u/(\d+)[""'][^>]*>([^<]*)</a>"; 高手你的这个是把,字符串给匹配下来了,里面的值没取到啊,谢谢你啦,在帮我一下呗
Group[1]是1950866865 Group[2]是公益富豪
_小黑_ 2012-12-20
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
string pattern=@"(?i)<a[^>]*?href=[""']http://weibo\.com/u/(\d+)[""'][^>]*>([^<]*)</a>";
高手你的这个是把,字符串给匹配下来了,里面的值没取到啊,谢谢你啦,在帮我一下呗
_小黑_ 2012-12-20
  • 打赏
  • 举报
回复
引用 5 楼 zhouqinghe24 的回复:
<A (class=\".+[^\"]\" )?href="http://weibo.com/u/(\d+)" target=_blank usercard=\"(.+[^\"])\" .+[^>]>(\w+[^<])</A>
出现好多意外字符
瑞卡哥哥 2012-12-20
  • 打赏
  • 举报
回复
<A (class=\".+[^\"]\" )?href="http://weibo.com/u/(\d+)" target=_blank usercard=\"(.+[^\"])\" .+[^>]>(\w+[^<])</A>
游离失所 2012-12-20
  • 打赏
  • 举报
回复
Match match = Regex.Match(string yourstr, "<A[\w\W]+?id=(\d+)">([\w\W]+?)</A>");
  • 打赏
  • 举报
回复
string input= <A class="W_f14 S_func1" href="http://weibo.com/u/1950836865" target=_blank usercard="id=1950836865">公益魏豪</A> <SPAN class=addr><EM class="W_ico12 male"></EM>辽宁 大连 </SPAN>;
Match =Regex.Match(input,"<A class=.+usercard=\"([0-9]+)\">(\w+)</A>")
value1 = Match.Groups[1].value
value2 = Match.Groups[2].value
游离失所 2012-12-20
  • 打赏
  • 举报
回复
Match match = Regex.Match("a", "<A[\w\W]+?id=(\d+)">([\w\W]+?)</A>"); string str1=match.group[1].value; string str2=match.group[2].value;
  • 打赏
  • 举报
回复
string pattern=@"(?i)<a[^>]*?href=[""']http://weibo\.com/u/(\d+)[""'][^>]*>([^<]*)</a>";

110,533

社区成员

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

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

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