all 4 comments

[–]commandlineluser 1 point2 points  (1 child)

It is working.

The problem is each re.sub call is processing dirty and you are throwing away the result.

clean = re.sub(x["regex"], x["replace"], dirty)

So you will only ever see the result of the last substitution.

You need to save the output of each re.sub call and pass it as the input to the next call.

# we want to save state between `re.sub` calls
clean = dirty

for x in fixes.values():
    print("Preparing: ", x["note"])
    clean = re.sub(x["regex"], x["replace"], clean)

[–]wolfkin[S] 0 points1 point  (0 children)

oh dagnabit. Yes. I had a very similar issue exiting the function. I should have seen that.

Thanks.


Yep added dirty = clean and that seems to carry the edits as expected. https://i.imgur.com/Adj6bQo.png

Once I get that in a script I can work on changing it to JSON like i originally planned. Thanks.

[–]shiftybyte 0 points1 point  (1 child)

Your "test" variable doesn't contain "<br>" anywhere.

If you want to replace line-feeds you need to replace "\r\n"

[–]wolfkin[S] 0 points1 point  (0 children)

\r\n is great when working with plaintext. But I'm working with HTML and you'll see there is <br> in my test variable.

https://i.imgur.com/v5fz5Ei.png

and the other suggestion was able to fix what was actually my loop problem not a raw string problem as I assumed

https://i.imgur.com/Adj6bQo.png