Is there any Tcl function to add escape character to a string automatically?
For example, I have a regular expression
"[xy]"
After I call the function, I get
"\[xy]"
After being called again, I get
"\\\[xy]"
I remember there’s such function with some script language, but I cannot recall which language it is.
The usual way of adding such escape characters as are “necessary” is to use
list(%is my Tcl prompt):The
listcommand prefers to leave alone if it can, wrap with braces if it can get away with it, and resorts to backslashing otherwise (because backslashes are really unreadable).If you really need backslashes,
string maporregsubwill do what you need. For example: