Hi Marco,

> On 23 Apr 2019, at 15:53, Marco Neumann <[email protected]> wrote:
> 
> I think I'm familiar with functions on strings in SPARQL but as far as
> I can see there is nothing similar to a grep like pattern matching and
> extraction on strings for SPARQL. Or is there one?

The replace function does pattern matching and allows extraction of matched 
sub-patterns:
https://www.w3.org/TR/sparql11-query/#func-replace 
<https://www.w3.org/TR/sparql11-query/#func-replace>
https://www.w3.org/TR/xpath-functions/#func-replace 
<https://www.w3.org/TR/xpath-functions/#func-replace>

    replace(input, pattern, replacement)

The special “variables” $1, $2, $3, and so on can be used in the replacement 
string. They refer to parts of the input that were matched by the first, 
second, third, and so on pair of parentheses in the regex pattern. For example:

    replace("23 April 2019", "^([0-9][0-9])", "$1")

would return "23" because that is the part of the input matched by the first 
(and only) pair of parentheses.

Also useful might be Jena’s own apf:strSplit property function:
https://jena.apache.org/documentation/query/library-propfunc.html 
<https://jena.apache.org/documentation/query/library-propfunc.html>

It can split a literal into multiple literals based on a regular expression.

Taken together, these two functions can do a wide range of pattern matching and 
extraction tasks.

Hope that helps,
Richard

Reply via email to