Most likely, you want to just use quotemeta, because your path separators in the form of backslashes are somewhere interpolated into a regular expression.
I don't see the code where you interpolate stuff into a regex, but if you look at where you do that, you should find the cause.
In reply to Re: Unterminated \g... pattern in regex behaving badly on Windows
by Corion
in thread Unterminated \g... pattern in regex behaving badly on Windows
by jkeenan1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |