2012-03-05 35 views
-1

我的表已經得到了與字符串像這樣的列:如何僅檢索SQLite中的域名?

"http://news.yahoo.com/whats-super-tuesday-419-gop-delegates-130610354.html" 
"http://www.nytimes.com/2012/03/05/us/politics/republican-party-moves-toward-romney-ahead-of-super-tuesday.html?_r=1&hp" 
"http://www.washingtonpost.com/2010/07/08/AB582vC_page.html" 

我想獲得此列:

"http://news.yahoo.com/" 
"http://www.nytimes.com/" 
"http://www.washingtonpost.com/" 

如何到達那裏?

+0

http://stackoverflow.com/questions/5071601/how- do-i-use-regex-in-a-sqlite-query – sha 2012-03-05 13:53:07

+0

歡迎使用Stack Overflow。請閱讀[如何問](http://stackoverflow.com/questions/how-to-ask),[你有什麼嘗試?](http://mattgemmell.com/2008/12/08/what-have - 你試過/),和[如何問問題的智能方式](http://catb.org/esr/faqs/smart-questions.html)。 – 2012-03-05 14:00:06

+0

對不起,但我沒有找到你指向的帖子中的答案:我不想找到一個查詢字符串,而是要替換它 – Matthieu 2012-03-05 14:16:06

回答

1

這是C#代碼,並使用.NET正則表達式,但如果你的正則表達式的味道是有點不同的,你可以根據需要調整:

using System.Text.RegularExpressions; 

Regex rx = new Regex("\"(http://.*?/)(.*?)\"", RegexOptions.IgnoreCase); 
string rxReplace = "\"$1\""; 

string input = "http://foo.com/fubar.html"; 

// Produces "http://foo.com/" 
string output = rx.Replace(input, rxReplace);