Python: how to get a number followed by a specific key word from a string
Question: Let's say I have a string like this:

    
    
    Benchmark\r\n\tRunning for engine innodb\r\n\tAverage number of seconds to run all queries: 0.374 seconds\r\n\tMinimum number of seconds to run all queries: 0.374 seconds\r\n\tMaximum number of seconds to run all queries: 0.374 seconds\r\n\tNumber of clients running queries: 1\r\n\tAverage number of queries per client: 2
    

If I'm only interested in the value followed by 'Average number of seconds to
run all queries:', how can I get it?


Answer: One overkill of this problem is to use the regular expression since the
regular expression is a general approach to deal with the patter matching.

For example, You can use the following code to solve your problem here:

    
    
    import re
    mystring = 'Your input'
    
    float_pattern = '(\d*\.\d*)'
    prefix = 'Average number of seconds to run all queries: '
    postfix = ' seconds'
    all_time = re.findall(prefix+float_pattern+postfix,mystring)
    all_time_t = map(lambda x:float(x),all_time)
    average_time = sum(all_time_t)/len(all_time_t)
    

Read the document for regular expression for more
information:<https://docs.python.org/2/library/re.html>

