我需要替换ip ospf db area <IP4ADDR> ex <IP4ADDR> rtr <IP4ADDR>
用ip ospf db area 0.0.0.1 ex 0.0.0.0 rtr 222.0.0.1
。你知道吗
我试过了,但不符合要求。你知道吗
>>> str = "ip ospf db area <IP4ADDR> ex <IP4ADDR> rtr <IP4ADDR>"
>>> newstr = str.replace("<IP4ADDR>","0.0.0.1")
>>> newstr
'ip ospf db area 0.0.0.1 ex 0.0.0.1 rtr 0.0.0.1'
为了得到期望的结果,所有3个IP地址都将被替换为不同的值。如果python中有任何可用的功能,有人能帮我吗?你知道吗
您可以传递一个可选参数
count
。根据Python文档:因此,您可以进行链式调用(这将起作用,因为
replace()
返回修改后的字符串):注意:这与执行以下操作几乎相同:
您可以向
re.sub
传递一个函数,该函数每次返回不同的替换字符串。例如:相关问题 更多 >
编程相关推荐