2010-08-07 65 views

回答

7

在處理as3corelib中的URI時有一個非常完整的實用程序類。也許你可能想用這個來代替滾動你自己的。

import com.adobe.net.URI; 
var uri:URI = new URI("http://www.google.com/translate"); 
trace(uri.authority); // traces www.google.com 
2

這應該做的工作:http(s?)://([\w]+\.){1}([\w]+\.?)+ 可以在GSkinner RegExr

0

嘗試此之前的正則表達式只要錯過了,我需要一些類型的URL,所以Google員工的利益,我用

(http:// | https://)?(www。)?[Az] *(.com | .co.uk | .us | .org | .net | .mobi)

in C#

var regexMatch = Regex.Match(input, @"(http://|https://)?(www.)?[A-z]*(.com|.co.uk|.us|.org|.net|.mobi)", RegexOptions.Multiline); 

string domain = regexMatch.Value; 

請參閱RegExr的示例。

您可以刪除刪除「(...)?」部分阻止該部分出現匹配,例如刪除我需要的http匹配。

可能不完美,但適合我。 This site是建立表達式的極好參考。