Я хочу получить дату и конкретный элемент в тексте, используя регулярное выражение в python 3. Ниже приведен пример:
text = '''
190219 7:05:30 line1 fail
line1 this is the 1st fail
line2 fail
line2 this is the 2nd fail
line3 success
line3 this is the 1st success process
line3 this process need 3sec
200219 9:10:10 line1 fail
line1 this is the 1st fail
line2 success
line2 this is the 1st success process
line2 this process need 4sec
line3 success
line3 this is the 2st success process
line3 this process need 2sec
'''
В приведенном выше примере я хотел бы получить все строки после 'successлиния'.Вот желаемый вывод:
[('190219','7:05:30','line3 this is the 1st success process', 'line3 this process need 3sec'),
('200219', '9:10:10', 'line2 this is the 1st success process', 'line2 this process need 4sec', 'line3 this is the 2st success process','line3 this process need 2sec')]
Я хочу попробовать это:
>>> newLine = re.sub(r'\t|\n|\r|\s{2,}',' ', text)
>>> newLine
>>> Out[3]: ' 190219 7:05:30 line1 fail line1 this is the 1st fail line2 fail line2 this is the 2nd fail line3 success line3 this is the 1st success process line3 this process need 3sec 200219 9:10:10 line1 fail line1 this is the 1st fail line2 success line2 this is the 1st success process line2 this process need 4sec line3 success line3 this is the 2st success process line3 this process need 2sec '
Я не знаю, как правильно получить результат.Я пробовал это, чтобы получить строку:
(\b\d{6}\b \d{1,}:\d{2}:\d{2})...
Как мне решить эту проблему?