日期:2014-05-17  浏览次数:20522 次

c#正则问题!为什么匹配不出下列网址?
string value = "http://forum.csdn.net/PointForum/Forum/PostTopic";
Match m = new Regex("http://forum.csdn.net/.*?").Match(value);
value = m.Value;

1:我想匹配出整条网址。但为什么value=http://forum.csdn.net/?
2:http://forum.csdn.net/PointForum/Forum/PostTopic 比如我想匹配网址是不是等于http://forum.csdn.net/PointForum/Forum要咋弄?但网址是http://forum.csdn.net/PointForum/Forum/也会匹配成功。后国有个“/”的时候

string value = "http://forum.csdn.net/PointForum/Forum/";
Match m = new Regex("http://forum.csdn.net/PointForum/Forum").Match(value);
value = m.Value;

上边的代码能成功 是不是应该加个[^/]类?但我加了不成功

------解决方案--------------------
C# code

Match m = new Regex("http://forum.csdn.net/.+").Match(value);

------解决方案--------------------
C# code

完全匹配:
http://forum.csdn.net/PointForum/Forum$

------解决方案--------------------
1. http://forum.csdn.net/\S*

2. 

string value = "http://forum.csdn.net/PointForum/Forum/";
Match m = new Regex("http://forum.csdn.net/PointForum/Forum/?").Match(value);
value = m.Value;