i have strings with Following pattern in python :
2011-03-01 14:10:43 C:\Scan\raisoax.exe detected Trojan.Win32.VBKrypt.agqw
how get substrings: C:\Scan\raisoax.exe and Trojan.Win32.VBKrypt.agqw
between string is tab
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.
just use the substring method of a python String.
s = r"2011-03-01 14:10:43 C:\Scan\raisoax.exe detected Trojan.Win32.VBKrypt.agqw"
s.split("\t")
gets you
['2011-03-01 14:10:43 C:\\\\Scan\\raisoax.exe detected', 'Trojan.Win32.VBKrypt.agqw']
s = r"2011-03-01 14:10:43 C:\Scan\raisoax.exe detected Trojan.Win32.VBKrypt.agqw"
v = s.split()
print v[-1] # gives you Trojan.Win32.VBKrypt.agqw
print v[-3] # gives you C:\Scan\raisoax.exe
To handle spaces in filenames try
print " ".join(v[2:-2])
C:\Program Files\fubar.exe ?