I'm working on a part of a project, which is repleacing http url's with https url's if possible.
The Problem is, that the regular expressions for that are written for the javascript regex parser, but I'm using that regex inside python. To be compatible, I would rewrite the regex during parsing into a valide python regex.
as example, I have that regular expression given:
https://$1wikimediafoundation.org/
and I would a regular expression like that:
https://\1wikimediafoundation.org/
my problem is that I doesn't know how to do that (converting $
into \
)
This code doesn't work:
'https://$1wikimediafoundation.org/'.replace('$', '\')
generate the following error:
SyntaxError: EOL while scanning string literal
This code work without error:
'https://$1wikimediafoundation.org/'.replace('$', '\\')
but generate a wrong output:
'https://\\1wikimediafoundation.org/'