简体   繁体   English

reg表达式以包括不以.com / .net / etc结尾的Intranet网站

[英]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\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)", "<a target='_blank' 
href='$1'>$1</a>");

This seems to be pretty accurate but fails on two things: 这似乎很准确,但是在两件事上失败了:

  1. I can't get it to recognize a url if its of the form www.yahoo.com 如果网址为www.yahoo.com则无法识别该网址
  2. I can't get it to work for intranet sites so something like http://mysite/Views/Issues/ListView.aspx doesnt link :( 我无法将其用于Intranet网站,因此类似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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM