I need to do this:
text = re.sub(r'\]\n', r']', text)
But with find
and replace
as variables:
find = '\]\n'
replace = ']'
text = re.sub(find, replace, text)
Where should I put r
(raw)? It is not a string.
The r''
is part of the string literal syntax:
find = r'\]\n'
replace = r']'
text = re.sub(find, replace, text)
The syntax is in no way specific to the re
module. However, specifying regular expressions is one of the main use cases for raw strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With