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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dcode
  • 223
  • 1
  • 14

1 Answers1

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)
Robᵩ
  • 163,533
  • 20
  • 239
  • 308