SPARQL 中的正则表达式:为什么 [[:alnum:]] 不 return 匹配?
Regex in SPARQL: Why [[:alnum:]] doesn't return matches?
我想找到特定网站对应的维基数据资源。这是我的查询
SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
?resource wdt:P856 ?website.
FILTER (REGEX(str(?website), 'http(s)?://(\w.)?smh.com.au/$')) .
}
}
(link here)
return 没有任何结果。这不是我所期望的,因为
SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
?resource wdt:P856 ?website.
FILTER (REGEX(str(?website), 'http(s)?://www.smh.com.au/$')) .
}
(link here)
模式\w
(写作\w
转义\
)意味着一个个字母,但你期望三个 w
个字母,据我理解。
要匹配三个 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?
我想找到特定网站对应的维基数据资源。这是我的查询
SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
?resource wdt:P856 ?website.
FILTER (REGEX(str(?website), 'http(s)?://(\w.)?smh.com.au/$')) .
}
}
(link here) return 没有任何结果。这不是我所期望的,因为
SELECT DISTINCT ?resource ?instanceOfLabel ?website
WHERE
{
?resource wdt:P856 ?website.
FILTER (REGEX(str(?website), 'http(s)?://www.smh.com.au/$')) .
}
(link here)
模式\w
(写作\w
转义\
)意味着一个个字母,但你期望三个 w
个字母,据我理解。
要匹配三个 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?