2024-09-16 20:19:38 发布
网友
从下面的输出中,我想得到端口描述的值
out = """Port Description - not advertised System Name - not advertised"""
截至目前,我正在使用以下代码:
re.search(r'Port Description\s+-\s+([\s\w]+)',out).group(1)
但是我得到的结果是:not advertised System Name
not advertised System Name
我的输出中只需要not advertised
not advertised
您应该在多行模式(flags=re.M)下搜索,并包括行尾标记'$':
flags=re.M
'$'
re.search(r'Port Description\s+-\s+([\s\w]+$)', out, flags=re.M).group(1) #'not advertised'
您应该在多行模式(
flags=re.M
)下搜索,并包括行尾标记'$'
:相关问题 更多 >
编程相关推荐