【问题标题】:Regex in SPARQL: Why [[:alnum:]] doesn't return matches?SPARQL 中的正则表达式:为什么 [[:alnum:]] 不返回匹配项?
【发布时间】:2016-08-15 04:50:27
【问题描述】:

我想查找与特定网站对应的 Wikidata 资源。这是我的查询

SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
    ?resource wdt:P856 ?website.
        FILTER (REGEX(str(?website), 'http(s)?://(\\w.)?smh.com.au/$')) .
  }           
} 

(链接here) 它不返回任何结果。这不是我所期望的,因为

SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
    ?resource wdt:P856 ?website.
        FILTER (REGEX(str(?website), 'http(s)?://www.smh.com.au/$')) .           
} 

(链接here

【问题讨论】:

  • 你猜(\\w.)是什么意思?我的意思是您希望与它匹配什么?它如何反映网站场景?

标签: regex sparql wikidata


【解决方案1】:

模式\w(写成\\w 转义\)表示一个字母,但据我所知,您期望三个 w字母。 p>

要匹配三个w,您应该使用

'http(s)?://(w{3}.)?smh.com.au/$'

不过,使用www有什么问题?

'http(s)?://(www.)?smh.com.au/$'

如果你想要任何三个字母使用

'http(s)?://(\\w{3}.)?smh.com.au/$'

也许您想要的任何字母都不止0

'http(s)?://(\\w+.)?smh.com.au/$'

我想,这个答案会对你有所帮助:How to represent a fix number of repeats in regular expression?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2012-10-07
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多