【问题标题】:How do I retrieve only the domain name in SQLite?如何只检索 SQLite 中的域名?
【发布时间】:2012-03-05 13:50:05
【问题描述】:

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

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

我怎么去那里?

【问题讨论】:

标签: regex sqlite query-string


【解决方案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 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 2019-02-20
    • 2014-04-03
    • 2019-07-27
    相关资源
    最近更新 更多