SPARQL replace "." to "_"
Asked Answered
F

1

5

I have a problem with my query. I need to search through variables and if there is . in a string I need to replace that specific character to _. I can replace empty spots and - but I have a problem replacing a dot.

BIND(replace(?input,".","_") AS ?output) .

I have tried also use /., //., \., \\., basically anything but the result is the same.

Lexical error. Encountered: "<" <40>, after: "replace"

Thank you in advance.

Fruge answered 17/5, 2016 at 7:57 Comment(0)
E
9

Escape the dot with \\.. You also might want to convert to string with STR:

BIND(REPLACE(STR(?input),"\\.","_") AS ?output) .

You can also replace all of the characters with the same replace (here you don't need to escape the dot):

BIND(REPLACE(STR(?input),"[. -]","_") AS ?output) .

REPLACE takes a regular expression as the second argument, that's why you need to escape the dot in the first one. In the second an escape is not needed as the dot is inside a character class.

Equality answered 17/5, 2016 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.