1 回答
TA贡献1786条经验 获得超13个赞
除了语言障碍,根据您的标准试试这个
>>> import re
>>> string = '''RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140116/cleanup/stat_KSHA500 --conf /export/home-V cisco -N -S -o -P telnet,ssh2
RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140200/cleanup/stat_KSHA11 --conf /export/home-V cisco -N -S -o -P telnet,ssh2
RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_1500/cleanup/stat_KSHA211 --conf /export/home-V cisco -N -S -o -P telnet,ssh2'''
>>> configs = re.findall('(?i)RemoteConfig[\S\s]*?ssh2(?=\s|$)', string)
>>> for config in configs:
print(config)
#Output
RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140116/cleanup/stat_KSHA500 --conf /export/home-V cisco -N -S -o -P telnet,ssh2
RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140200/cleanup/stat_KSHA11 --conf /export/home-V cisco -N -S -o -P telnet,ssh2
RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_1500/cleanup/stat_KSHA211 --conf /export/home-V cisco -N -S -o -P telnet,ssh2
>>> configs
#Output
['RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140116/cleanup/stat_KSHA500 --conf /export/home-V cisco -N -S -o -P telnet,ssh2', 'RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_140200/cleanup/stat_KSHA11 --conf /export/home-V cisco -N -S -o -P telnet,ssh2', 'RemoteConfig cleanup.txt --prefix /tftpboot/sites --status /tftpboot/190315_1500/cleanup/stat_KSHA211 --conf /export/home-V cisco -N -S -o -P telnet,ssh2']
添加回答
举报