How to unescape second argument of Str.global_replace

"[email protected] [ocaml_beginners]" <[email protected]> 04 Oct 2016 02:32:50 -0700
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
I need to use Str.global_replace as follows :

   Str.global_replace regexp templ s
   
The problem is that my templ string contains lots of
backslashes (including doubles and tripled backslashes)
which I don't want to be interpreted by  Str.global_replace
as explained in the documentation at 
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html#VALglobal_replace) http://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html#VALglobal_replace)

   

So I basically need to "unescape the backslashes" in templ ;
is there a built-in function to do this ?

Below is an example showing why unescaping is needed (it raises an Illegal backslash sequence exception) :


let rgxp=Str.regexp(Str.quote "x");;
let replacement="'([\\w\\!\\#$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`{\\|\\}\\";;
let result=Str.global_replace rgxp replacement "x";;