如何在SQLite中仅检索域名?

时间:2012-03-05 13:50:06

标签: regex sqlite query-string

我的表有一个包含这样字符串的列:

"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/"

我如何到达那里?

1 个答案:

答案 0 :(得分: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 );