You can try
(\\?.)
and replace with [$1]
See it on Regexr.
?
is a shortcut quantifier for 0 or 1 occurences, so the above pattern is matching a character and an optional backslash before. If ?
is not working (I don't know lua) you can try {0,1}
instead. That is the long version of the same.