Problem with Replacing special characters in a string
Posted
by
Hossein
on Stack Overflow
See other posts from Stack Overflow
or by Hossein
Published on 2011-03-10T16:06:16Z
Indexed on
2011/03/10
16:10 UTC
Read the original article
Hit count: 314
Hi,
I am trying to feed some text to a special pupose parser. The problem with this parser is that it is sensitive to ()[]
characters and in my sentence in the text have quite a lot of these characters. The manual for the parser suggests that all the ()[]
get replaced with \( \) \[ \]
. So using str.replace
i am using to attach \
to all of those charcaters. I use the code below:
a = 'abcdef(1234)'
a.replace('(','\(')
however i get this as my output:
'abcdef\\(1234)'
What is wrong with my code? can anyone provide me a solution to solve this for these characters?
© Stack Overflow or respective owner