Justin Ezequiel wrote:
> will try to convince my colleague to use string formatting
> if he insists on regexp then he can do
> re.sub(r'(?i)', apppath.replace('\\', ''), template)
>
> re.escape does not quite work for my example
>
re.sub(r'(?i)', re.escape(apppath), template)
> 'C\\:\\n
Kent wrote:
"""The problem is that the re engine itself is interpreting the backslashes
in the replacement pattern.
With a single slash you get a newline even though the slash is a literal
in the replacement string:
So if you want a literal \ in your replacement text you have to escape
the \, ev
Justin Ezequiel wrote:
> a colleague demonstrated a problem he had with regular expressions
>
apppath = os.path.abspath(os.curdir)
apppath
> 'C:\\napp_and_author_query\\napp_and_author_query\\a b c d'
template = r'\files'
template
> '\\files'
re.sub(r'(?i)', apppath, templ
a colleague demonstrated a problem he had with regular expressions
>>> apppath = os.path.abspath(os.curdir)
>>> apppath
'C:\\napp_and_author_query\\napp_and_author_query\\a b c d'
>>> template = r'\files'
>>> template
'\\files'
>>> re.sub(r'(?i)', apppath, template)
'C:\napp_and_author_query\napp_