I am trying to extract 2 variables from a string in the following form
2015-11-07 10:04:30,855 INFO - RequestTimeLogger.logRequestTime(11) | Request to 'Get Cases (Between Dates)' took 514ms
I am trying to extract Get Cases (Between Dates) and the response time 514
I have tried the following using Python 2.7.6
reg = re.compile("(.+')(?P<request_name>.*)(' took )(?P<request_time>\d+)(.*)")
reg.match(mystringabove)
which returns false... What am I doing wrong?
The request name is always within quotes like 'something' and can be any character that isn't a quote
The request time is always before ms
'([^']+)'.*?(\d+)re.compile(r"(.+')(?P<request_name>.*)(' took )(?P<request_time>\d+)(.*)")reg.match()returns a match object with the named groups matching exactly what you want. (also tested on regex101.com/#python)