Skip to main content
 首页 » 编程设计

python之python中的子串

2025年05月04日12oomusou

我在 python 中有以下模式的字符串:

2011-03-01 14:10:43 C:\Scan\raisoax.exe detected    Trojan.Win32.VBKrypt.agqw 

如何获取子串:C:\Scan\raisoax.exe and Trojan.Win32.VBKrypt.agqw

字符串之间是制表符

请您参考如下方法:

使用正则表达式的解决方案:

s = "2011-03-01 14:10:43 C:\Scan\raisoax.exe detected    Trojan.Win32.VBKrypt.agqw" 
reg = re.match(r"\S*\s\S*\s(.*)[^\ ] detected\s+(.*)",s) 
file,name = reg.groups() 

这也会捕获其中包含空格的文件。如果您的文件中包含“detected ”,它将失败。 (您也可以添加一个前向断言来解决这个问题。