我有一个包含大写单词的文件,我需要通过文件将它们更改为小写整数。我使用下面的代码来更改它们,但只有第一个字符被更改。我想更改标签SC(全局)中可用的全部内容。
$xtx1 =~ s/<sc>(.*?)<\/sc>/\l$1/g;
答案 0 :(得分:0)
尝试下一个
filePath = 'sample.txt';
# Go line by line and change to lowercase
tmpPath = mkstemp()
with open(tmpPath, 'w') as newFile:
with open(filePath) as oldFile:
for line in oldFile:
# Apply pattern
tmp = re.sub('^(.*?)\<\/sc\>.*', lambda m: m.group(0).lower(), line)
newFile.write(tmp)
close(oldFile)
close(newFile)
# Remove original file
remove(filePath)
# Move new file
move(tmpPath, filePath)