python的re正则表达式怎么写

2022-04-12 社会 111阅读
>>>s="""#serverxx-3:80weight=1max_fails=2fail_timeout=10sbackup;
serverxx:80weight=1max_fails=2fail_timeout=10s;
serveryyweight=1max_fails=2fail_timeout=10sbackup;
server192.168.1.1weight=1max_fails=2fail_timeout=10s;
serverxx:9090max_fails=2fail_timeout=10sbackup;
server192.168.1.1weight=1max_fails=2fail_timeout=10s;
"""
>>>importre
>>>re.findall('^[^#\n]*server[\t]+([^:\s]+)',s,re.M)
['xx','yy','192.168.1.1','xx','192.168.1.1']
>>>
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com