#!/usr/bin/python # -*- coding: utf-8 -*- import re f = open('PB_Backup.vcf') contents = f.read() f.close() def replace_phones(matchobj): return matchobj.group('begin')+matchobj.group('number')[1:]+matchobj.group('end') regex = ur'(?PTEL.+:)(?P\d{11})(?P.+)' output = re.sub(regex, replace_phones, contents) f = open('PB_Result.vcf', 'wb') f.write(output) f.close()