可能重复: 正则表达式的网址,包括查询字符串
我有一个文本或消息。
嘿!试试这个 http://www.test.com/test.aspx?id=53
我们的要求是使用下面的code,以获得从text.We链接
名单,其中,串>名单=新的名单,其中,串>();
正则表达式urlRx =新
正则表达式(@(小于网址>(HTTP:| HTTPS:[/] [/] | WWW)([AZ] | [AZ] | [0-9] | [/] | [〜])? *),
RegexOptions.IgnoreCase);
MatchCollection匹配= urlRx.Matches(消息);
的foreach(在比赛中赛赛)
{
list.Add(match.Value);
}
返回列表;
它给出的网址,但的code不完整的one.Output是
http://www.test.com/test.aspx
但是,我们需要完整的URL像
http://www.test.com/test.aspx?id=53
请建议如何解决issue.Thanks提前。
解决方案试试这个正则表达式,返回查询字符串也
(http|ftp|https)://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?您可以在 gskinner
测试Possible Duplicate: regex for URL including query string
I have a text or message.
Hey! try this http://www.test.com/test.aspx?id=53
Our requirement is to get link from a text.We are using following code
List<string> list = new List<string>();
Regex urlRx = new
Regex(@"(?<url>(http:|https:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)",
RegexOptions.IgnoreCase);
MatchCollection matches = urlRx.Matches(message);
foreach (Match match in matches)
{
list.Add(match.Value);
}
return list;
It gives url but not the complete one.Output of the code is
http://www.test.com/test.aspx
But we need complete url like
http://www.test.com/test.aspx?id=53
Please suggest how to resolve that issue.Thanks in advance.
解决方案Try this regex, returns the query string also
(http|ftp|https)://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?
You can test it on gskinner
上一篇:在SQL Server中领先和落后落后、SQL、Server
下一篇:为什么Enumerable.Count()会抛出`InvalidOperationException`将`null`转换为`bool`?转换为、抛出、Count、Enumerable