Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL replace "." to "_"

Tags:

sparql

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.

like image 816
Eduard Dindoffer Avatar asked Mar 12 '23 07:03

Eduard Dindoffer


1 Answers

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.

like image 83
evsheino Avatar answered May 03 '23 01:05

evsheino