I have this Perl regular expression and I want to convert it to Python.
The regex I want is a search and replace that finds text and converts it to upper case. It also must be the first occurring result. Perl regex:
open FILE, "C:/thefile.txt";
while (<FILE>){
# Converts "foo yadayada bar yadayada"
# to "FOO bar yadayada"
s/(^.*?)(yadayada)/\U$1/;
print;
}
The Python regex I have is not working correctly:
import re
lines = open('C:\thefile.txt','r').readlines()
for line in lines:
line = re.sub(r"(yadayada)","\U\g<1>", line, 1)
print line
I realize the \U\g<1> is what isn't working because Python doesn't support \U for uppercase.. so what do I use!?!
s/(yadayada)/\U$1/? `