I am trying to find all Wikidata items whose P18 property is an URL that has the word "Montage" anywhere in its filename.


enter image description here

I managed to find items by their complete P18 filename:

SELECT ?item
  ?item wdt:P18 <http://commons.wikimedia.org/wiki/Special:FilePath/Montage%20Columbus%201.jpg>.

But now I would like to add wildcards to that. My attempts with * and contains/regex all failed.

How to achieve that?

  • w.wiki/7gq 416 results Commented Aug 30, 2019 at 19:15
  • 1
    @StanislavKralin: Wonderful, it works, thanks! And the hint:Query trick is gold. Feel free to post an answer containing the query, so that I can accept it. If not I will post and accept myself ^_^
    – Nicolas Raoul
    Commented Aug 31, 2019 at 6:21
  • please feel free to post an answer yourself! Commented Sep 1, 2019 at 19:41

2 Answers 2


The trick is to use str inside the contains.

This query gives the expected result:

select ?item ?img
  hint:Query hint:maxParallel 400 .
  hint:Query hint:chunkSize  8000 .
  ?item wdt:P18 ?img . 
  filter contains(str(?img), "Montage")

Try it

Another way to achieve this is to set hint:Query hint:regexMatchNonString true and then use a normal regex.

(Huge thanks to Stanislav Kralin who found all this)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.