I'm using the regexlib to come up with a regular expression to get a url out of a string.
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
http://mysite/Views/Issues/ListView.aspx
doesnt link :( 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.