python中的子字符串 [英] substring in python

查看:24
本文介绍了python中的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have strings with Following pattern in python :

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

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

how get substrings: C:\Scan\raisoax.exe and Trojan.Win32.VBKrypt.agqw

字符串之间是制表符

推荐答案

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

A solution using regexes:

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()

这也会捕获带有空格的文件.如果其中包含检测到"的文件,它将失败.(你也可以添加一个前向断言来解决这个问题.

This will catch files with spaces in them as well. It will fail if you have files with " detected " in them. (you can add a forward assertion to fix that as well.

这篇关于python中的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆