When using regexes in SPARQL, a common cause of error is to search for URIs rather than strings. Using a regex over a URI is not possible in SPARQL, so you would convert a query like this:
prefix : <http://stardog.com/tutorial/>
SELECT *
WHERE {
?band :member ?soloartist
FILTER ( REGEX(?band, ".*" ) )
}
to this:
prefix : <http://stardog.com/tutorial/>
SELECT ?soloartist ?band
WHERE {
?band :member ?soloartist
FILTER ( REGEX(str(?band), ".*" ) )
}
Once this issue is solved, a common pitfall is to include angle brackets in the regex pattern, like this:
FILTER(REGEX(str(?band), "<http://stardog.com/tutorial/The_Beatles>"))
The problem with this is that the angle brackets are not included in the string representation of a URI. Instead, you would filter for The Beatles like so:
FILTER(REGEX(str(?band), "http://stardog.com/tutorial/The_Beatles"))
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article