我需要匹配字符串一样:'2017-08-09,08:59:20.445 INFO {peers_peak_parameters_grid} [eval_peers_peak] Evaluating batch 0 out of 2158',
蟒蛇重新匹配字符串整数
我已经尝试了不同的正则表达式,如:comp = re.compile("Evaluating batch ^[-+]?[0-9]+$ out of ^[-+]?[0-9]+$")
,这是一个例子用法:
def get_batch_process_time(log):
loglines = log.splitlines()
comp = re.compile("Evaluating batch ^[-+]?[0-9]+$ out of ^[-+]?[0-9]+$")
times = []
matches = []
for i, line in enumerate(loglines):
if comp.search(line):
time = string2datetime(line.split(' ')[0])
times.append(time)
matches.append(line)
return np.array(times), matches
不幸没有一条线似乎符合给定的模式。我假设我使用了错误的正则表达式。
什么是正确的正则表达式? 我正在使用re
吗? (我应该使用匹配而不是搜索吗?)
你的字符串没有'out'。 ['评估批处理[ - +]?[0-9] +出[ - +]?[0-9] +'](https://regex101.com/r/B3hqgw/1)似乎工作,如果它确实。 –
抱歉在这个问题上有错误。我已编辑示例字符串 – Donbeo
使用此模式:'评估批[0-9] {4}中的[0-9] {4}' – hadi