Hello, I am trying to create a program that will allow me to find a certain phrase, (always between brackets and always with a "'0" in it) and replace it. Basically I have something like [ k '0 ir e ] and what I need to do is use regular expressions to replace it with k_ir_e.
Also want the output to be to a different text file, leaving everything in the file the same but changing the phrase like above. (This is a syllabification document)
What I have been wresting with is getting my program to seemingly work with re.sub
I can't get even simple find and subs to work.
This is what I have so far, yet it can't even find exact words and replace them let alone regex. Any help would be great. Thanks.
#!/usr/bin/env python
import re
#Open the SyllRaw text file so that it can be read
file = open('syllRaw.txt','r')
#Create a new file where our output will be stored
new = open('wordSyll.txt', 'w')
#Set text to contain contents of syllraw file
text = file.read()
#create variable for desired search pattern
match = re.compile(r'm')
for words in text:
fixed = match.sub(r')