I use this line in a SPARQL query in my python program:
FILTER regex(?name, "%s", "i" )
(where %s is the search text entered by the user)
I want this to match if either ?name or ?featurename contains %s , but I cannot find any documentation or tutorial on using regex (). I tried a couple of things that seemed reasonable:
FILTER regex((?name | ?featurename), "%s", "i" ) FILTER regex((?name || ?featurename), "%s", "i" ) FILTER regex((?name OR ?featurename), "%s", "i" ) FILTER regex((?name, ?featurename), "%s", "i" )
and each of them without ()
FILTER regex(?name, "%s", "i" ) || regex(?featurename, "%s", "i" )
What is the right way to do this? Thanks
UPDATE: Using UNION. But I realized that it also works if you just repeat the regex part () like this:
FILTER (regex(?name, "%s", "i") || regex(?featurename, "%s", "i" ))
Both solutions seem a bit confusing in that you need to use a two-element tuple with copies of the same string to fill as %s s.
python filter regex sparql
Jeff
source share