嗨我試圖從下面的多行字符串的開始處提取IP和數字。我已經在pythex.org,pyregex.com和regex101.com上成功測試過它,但是在腳本執行時它不起作用。正則表達式的輸出如下。 (使用的paramiko到SSH從Cisco路由器中提取)Python正則表達式在3個在線測試器上成功測試,但不能在代碼中工作
多行字符串:
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#
我正則表達式如下(我也嘗試以傳統的方式使用正則表達式的標誌,即作爲重.M):
re3=re.findall(r"(?im)^(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\s+\b4\b.+\s+(\b\d{1,4}\b)$", string1)
當我運行下面的代碼:
print(type(string1))
print(type(re3))
print(len(re3))
print(re3)
輸出如下:
<class 'str'>
<class 'list'>
0
[]
我錯過了什麼嗎?
能告訴你'打印(再版(字符串1))'的輸出? – falsetru
'sh ip bgp summ |在192.168.190。\ r \ n192.168.190.3 4 100 193 196 17 0 0 02:51:20 3 \ r \ n192.168.190.4 4 100 195 197 17 0 0 02:50:42 4 \ r \ nR1#' – lycan1385