1 year ago

#384220

test-img

user4035

How to escape a symbol in Prolog using re_replace

I tried to use re_replace to replace characters in string. For example:

?- re_replace("_"/g, "QW", "a_b_c", Str).
Str = "aQWbQWc".

Then I tried to replace _ with \_. The documentation says:

Because \ is an escape character inside strings, you need to write "\\\\" to get a single backslash.

So I tried:

?- re_replace("_"/g, "\\\\_", "a_b_c", Str).
false.

For some reason I get false. What's wrong? How can I get a\_b\_c from a_b_c?

SWI Prolog version: 8.2.1.

prolog

escaping

0 Answers

Your Answer

Accepted video resources