[英]Reg expression to include intranet sites that dont end in .com / .net / etc
I'm using the regexlib to come up with a regular expression to get a url out of a string. 我正在使用regexlib提出正则表达式以从字符串中获取URL。
So far I have the following: 到目前为止,我有以下内容:
message = Regex.Replace(message, @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+
([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)", "<a target='_blank'
href='$1'>$1</a>");
This seems to be pretty accurate but fails on two things: 这似乎很准确,但是在两件事上失败了:
www.yahoo.com
www.yahoo.com
则无法识别该网址 http://mysite/Views/Issues/ListView.aspx
doesnt link :( http://mysite/Views/Issues/ListView.aspx
不会链接:( I despise regular expressions and could really use some help. 我鄙视正则表达式,确实可以使用一些帮助。
How about: 怎么样:
EDIT: 编辑:
resultString = Regex.Replace(subjectString, @"(\b(?:(?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Z0-9+&@#/%?=~_|$!:,.;]*[-A-Z0-9+&@#/%=~_|$]|((?:mailto:)?[A-Z0-9._%+-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})\b)|""(?:(?:https?|ftp|file)://|www\.|ftp\.)[^""\r\n]+""|'(?:(?:https?|ftp|file)://|www\.|ftp\.)[^'\r\n]+')", "$1", RegexOptions.IgnoreCase | RegexOptions.Multiline);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.