Matching of strings in SPARQL?

Kobojunkie picture Kobojunkie · Jun 17, 2012 · Viewed 10.7k times · Source

In ANSI SQL, you can write something like:

Select * From DBTable Where DBTable.Description LIKE "MEET"

or

Select * From DBTable Where DBTable.Description LIKE "%MEET%"

What I would like help with is writing the SPARQL equivalent of the above please.

Answer

toniedzwiedz picture toniedzwiedz · Jun 17, 2012

Use a regex filter. You can find a short tutorial here

Here's what it looks like:

PREFIX ns: <http://example.com/namespace>

SELECT ?x
WHERE
{ ?x ns:SomePredicate ?y .
  FILTER regex(?y, "YOUR_REGEX", "i") }

YOUR_REGEX must be an expression of the XQuery regular expression language

i is an optional flag. It means that the match is case insensitive.