2024-05-12 17:07:08 发布
网友
给定以下字符串:
dpkg.log.looker.test.2019-09-25
我想提取:
looker.test 或者
looker.test
looker。你知道吗
looker
我已经尝试了多种组合,但没有一种真正只提取主机名。如果我试图过滤整个文件(dpkg.对数,它也会忽略后面的字符:/[^dpkg.log].+(?=.[0-9]{4}-[0-9]{2}-[0-9]{2})/
/[^dpkg.log].+(?=.[0-9]{4}-[0-9]{2}-[0-9]{2})/
返回:er.test
er.test
有没有办法忽略整个字符串”dpkg.对数“不忽略后面重复的字符?你知道吗
也许,下面的表达式可以与re.findall配合使用:
re.findall
[^.]+\.[^.]+\.(.+)\.\d{2,4}-\d{2}-\d{2}
Demo
import re regex = r'[^.]+\.[^.]+\.(.+)\.\d{2,4}-\d{2}-\d{2}' string = ''' dpkg.log.looker.test.2019-09-25 dpkg.log.looker.test1.test2.2019-09-25 ''' print(re.findall(regex, string))
['looker.test', 'looker.test1.test2']
也许,下面的表达式可以与
re.findall
配合使用:Demo
测试
输出
相关问题 更多 >
编程相关推荐