#!/usr/bin/python3 # -*- coding: utf-8 -*- import re def main(): asr_result = """ sample rate: 8000 sample number: 39120 do StreamingVad Init... 5 3520 VadFlagPrepare 3820 VadFlagSpeaking 4360 VadFlagNoSpeech 4360 VadFlagPrepare 4600 VadFlagSpeaking """ pattern = r"(\d+)[\r\n]+VadFlagPrepare[\r\n]+(\d+)[\r\n]+VadFlagSpeaking[\r\n]+(\d+)[\r\n]+VadFlagNoSpeech[\r\n]+(\d+)[\r\n]+VadFlagPrepare[\r\n]+(\d+)[\r\n]+VadFlagSpeaking" # pattern = r"(\d+)[\r\n]+VadFlagNoSpeech" match = re.search(pattern, asr_result, flags=re.IGNORECASE | re.DOTALL) if match is not None: print(match.group(0)) print("-" * 15) print(match.group(1)) print("-" * 15) print(match.group(2)) print("-" * 15) print(match.group(3)) print("-" * 15) print(match.group(4)) print("-" * 15) print(match.group(5)) return if __name__ == '__main__': main()