0

I am replacing string content as:

re.sub(all, val, parsedData['outData'])

where all contains some round braces and might contain other characters.

>>> print all PICDSPVERS="DspFw:1.0008(1.0008),Fpga1:2.0925(2.0925),Fpga2:1.0404(1.0404),Mcu:1.0000(1.0000)"

Because of which matching fails. The pattern is coming from some interface, so I don't want to put \\ in the data.

I tried with 'r' and re.U option also, but still the match fails.

re.search('PICDSPVERS="DspFw:1.0008(1.0008)', parsedData['outData'])

How can we direct Python to treat a matching pattern as a string?

I am using Python 2.x.

0

1 Answer 1

2

If you don't want the matching pattern to be treated as a regular expression, then don't use re.sub. For plain strings, use str.replace(), like so:

new_outData = parsedData['outData'].replace(all, val)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.