Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

Remember that backslash escapes are only a Python syntactic feature. If you 
read data from a file, or from the input() builtin, that contains a backslash, 
it remains a backslash:

    >>> s = input()
    a\b
    >>> print(len(s), s == r'a\b')
    3 True

Backslashes are only special in two cases: as source code, and when displaying 
a string (or bytes) using `repr`.

So if you get a regex from the user, say by reading it from a file, or from 
stdin, or from a text field in a GUI, etc. and that regex contains a backslash, 
your string will contain a backslash and you don't need anything special.

Does this solve your problem?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44308>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to