I'm trying to get numerous values out of a pretty complex string that looks like this -
s = '04/03 23:50:06:242[76:Health]: (mem=188094936/17146904576) Queue Size[=:+:-] : Core[Compiler:0:0:0,HighPriority:0:74:74,Default:6:1872:1874,LowPriority:0:2:2]:Special[Special:0:2:2]:Event[Event:0:0:0]:Comm[CommHigh:0:1134:1152,CommDefault:0:4:4]'
These are the values I need to scan for -
list = ['Compiler', 'HighPriority', 'Default', 'LowPriority', 'Special', 'Event', 'CommHigh', 'CommDefault']
My intention is to get the 3 numbers after each string so in the example of HighPriority I would get [0, 74, 74] which I can then do something with each item.
I've used the below but it doesn't account for when the end of the string isn't a comma.
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
for l in list:
print l
print find_between( s, l + ':', ',' ).split(':')
\d\w\++\?\(\)I freeze because it's just not easy for me to read :(r = re.search('Compiler:([0-9]+):([0-9]+):([0-9]+)', s)should get you started. User.groups()to get the three substrings containing the numbers.re.searchinstead ofre.find.takewhilewith a''.join(see my edited answer).