【发布时间】:2019-11-21 03:29:06
【问题描述】:
我想将一些变量放入一个正则表达式中,同时也保持一个正则表达式模式。
regex = 'set groups {group} routing-instances (?P<routing_instances>[\w\W]+) interface {logical_interface}'.format(
group=group,
logical_interface=logical_interface
)
但是,它会转义转义字符:
ipdb> regex
'set groups GROUP1 routing-instances (?P<routing_instances>[\\w\\W]+) interface a10.555'
【问题讨论】:
-
尝试在你的字符串前加上 r''
标签: python regex python-3.x