regex - replace as raw string in python -


this question has answer here:

just minor query. new python. replacing string content as:

re.sub(all, val, parseddata['outdata'])

where all contains round braces, , might contain other characters.

>>> print picdspvers="dspfw:1.0008(1.0008),fpga1:2.0925(2.0925),fpga2:1.0404(1.0404),mcu:1.0000(1.0000)"

because of matching fails. pattern coming interface, don't wanna put \ in data.

i tried 'r' , re.u option also, still match fails.

re.search('picdspvers="dspfw:1.0008(1.0008)',parseddata['outdata'])

how can direct python treat matching pattern string.

fyi, using python2.x

if don't want matching pattern treated regular expression, don't use re.sub. plain strings, use str.replace(), so:

new_outdata = parseddata['outdata'].replace(all, val) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -