python处理正则表达式

import re

with open(r"C:\Users\Jhm\Desktop\input.txt","r",encoding="utf8") as src_file:
    with open(r"C:\Users\Jhm\Desktop\output.txt","w") as target_file:
        while True:
            str = src_file.readline()
            if not str:
                break
            pattern1 = '(\d{5})'
            pattern2 = "(CCID\((.*?)\))"
            result1 = re.search(pattern1, str)
            result2 = re.search(pattern2, str)
            text1 = result1.group()
            text2 = result2.group()
            Str1 = str.replace(text1, "")
            Str2 = Str1.replace(text2, "post(Y)")
            print(Str2)
            target_file.write(Str2)

你可能感兴趣的:(python处理正则表达式)