str.replace()
v2 |
v3无法识别正则表达式。
要使用正则表达式执行替换,请使用
re.sub()
v2 |
v3。
例如:
import reline = re.sub(r"(?i)^.*interfaceOpDataFile.*$", "interfaceOpDataFile %s" % fileIn, line )
import reregex = re.compile(r"^.*interfaceOpDataFile.*$", re.IGNORECASE)for line in some_file: line = regex.sub("interfaceOpDataFile %s" % fileIn, line) # do something with the updated line
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)