获取URL从文本 [英] Get url from a text
本文介绍了获取URL从文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
正则表达式的网址,包括查询字符串
我有一个文本或消息。
我们的要求是使用下面的code,以获得从text.We链接
名单,其中,串>名单=新的名单,其中,串>();
正则表达式urlRx =新
正则表达式(@(小于网址>(HTTP:| HTTPS:[/] [/] | WWW)([AZ] | [AZ] | [0-9] | [/] | [〜])? *),
RegexOptions.IgnoreCase);
MatchCollection匹配= urlRx.Matches(消息);
的foreach(在比赛中赛赛)
{
list.Add(match.Value);
}
返回列表;
它给出的网址,但的code不完整的one.Output是
但是,我们需要完整的URL像
请建议如何解决issue.Thanks提前。
解决方案
试试这个正则表达式,返回查询字符串也
<$p$p><$c$c>(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
But we need complete url like
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
这篇关于获取URL从文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文