I have a file which contains in it several lines of problematic syntax, I'd like to do find all occurrences of it and replace it with acceptable syntax.
Example:
<field id="someId" type="xs:decimal" bind="someId">
<description/>
<region id="Calc.R_315.`0" page="1"/>
<region id="Calc.R_315.`1" page="1"/>
</field>
I'd like to a string replacement of all occurrences of
<dot><tick><number> i.e. .`0 or .`1 or .`2 et cetera
with
<dash><number> i.e. -1 or -2 or -3
Notice it begins at 1 instead of 0.
I have the following python code which performs an inline replacement of however it starts at 0, I'd like it to start at 1.
with fileinput.input(files="file.xml", inplace=True, backup='.original.bak', mode='r') as f:
for line in f:
pattern = "\.`(\d+)"
result = re.sub(pattern, lambda exp: "-{}".format(exp.groups()[0]), line)
print(result, end='')
How to accomplish my goal?
format()function work?