2012-03-05 69 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);