Eduard Dindoffer
Eduard Dindoffer

Reputation: 73

SPARQL replace "." to "_"

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.

Upvotes: 5

Views: 3994

Answers (1)

evsheino
evsheino

Reputation: 2277

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.

Upvotes: 9

Related Questions