'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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source