Reputation: 1044
I'd like to remove all non-alphanumeric characters from a string in SPARQL.The following returns an error:
SELECT * WHERE {
?s ?p ?o .
BIND(REPLACE(?o, "/[^a-zA-Z0-9\s]/", "", "i") AS ?o2) .
}
Upvotes: 1
Views: 1361
Reputation: 9434
REPLACE
only works on string literals. ?o
is often a URI.
Also, you probably need to escape your escape character. \s
should be \\s
or more simply, just .
Or, you could try using the \W
wildcard (which should probably be \\W
in the query).
Try this (sample results against the DBpedia endpoint) --
SELECT *
WHERE
{
?s ?p ?o .
BIND(REPLACE(STR(?o), "\\W", "", "i") AS ?o2) .
}
LIMIT 5
Upvotes: 4