圖像鏈接here。 我有以下的路由器輸出:簡單的Python正則表達式來分隔單詞
config t
Enter configuration commands, one per line. End with CNTL/Z.
n7k(config)# port-profile demo_ethernet
n7k(config-port-prof)# ?
bandwidth Set bandwidth informational parameter
beacon Disable/enable the beacon for an interface
cdp Configure CDP interface parameters
channel-group Configure port channel parameters
delay Specify interface throughput delay
description Enter port-profile description of maximum 80 characters
從上面的輸出,我想這一點:
['bandwidth' , 'beacon' , 'cdp' , 'channel-group' , 'delay' , 'description']
我想
m = re.compile('(\w+\s\w+)')
n = m.findall(buffer)
並得到這樣的輸出:
['config t', 'Enter configuration', 'one per', 'End with', 'profile demo_ethernet', 'Set bandwidth', 'informational parameter', 'enable the', 'beacon for', 'an interface', 'Configure CDP', 'interface parameters', 'Configure port', 'channel parameters', 'Specify interface', 'throughput delay', 'Enter port', 'profile description', 'of maximum', '80 characters']
匹配的規則是什麼? –
我想要左側的按鍵。並在第一個四行後。 – ursandy
請正確格式化您的數據。它顯示爲一個長字符串。 –