I'm trying to match any instances of '1c' in a text file and replace them using re in Python. I've tried many different combinations using positive lookahead, but still no success. It would be great if anyone better than me with Regex could point me in the right direction.
Here's my script:
import re
with open('lorem.txt', 'r') as f:
data = f.read()
print(re.sub("1(?=c)", "</h1>", data))
And the text file:
Lorem hello dolor sit amet,
1consetetur sadipscing elitr 1c, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem hello dolor sit amet. Lorem hello dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem hello dolor sit amet. Lorem hello dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem hello dolor sit amet.
I only want to match the 1c, not the 1, and replace it with a closed h1 tag.
Thus far I've tried amongst others:
"1\(?=c\)"
"1/(?=c)"
"1$(?=c)"
"^(1c)$"
Any help would be much appreciated.