嗨,我正在尝试从下面的多行字符串的开头提取IP和结尾的数字。我已经成功地测试过了pythex.org网站, pyregex.com网站以及regex101.com,但在执行脚本时它不起作用。regex语句的输出如下。在
多行字符串(从使用paramiko到SSH的Cisco路由器提取):
sh ip bgp summ | in 192.168.190.
192.168.190.3 4 100 166 169 17 0 0 02:27:11 3
192.168.190.4 4 100 169 171 17 0 0 02:26:33 4
R1#
我的regex如下所示(我还尝试以常规方式使用regex标志,即re.M):
^{pr2}$当我运行以下代码时:
print(type(string1))
print(type(re3))
print(len(re3))
print(re3)
输出如下:
<class 'str'>
<class 'list'>
0
[]
我错过什么了吗?在
字符串包含回车符(
\r
,CR)。在调整正则表达式以匹配CR;在
$
之前添加\r?
(使用\r?
使CR可选)^{pr2}$
相关问题 更多 >
编程相关推荐