1 回答

TA貢獻1815條經驗 獲得超13個贊
這應該可以解決問題:^\[(.*?)\](?:\[(.*?)\])?->([a-zA-Z ]+)。確保您使用的是多行標志。這是一個Python演示:
>>> for x in re.finditer(r'^\[(.*?)\](?:\[(.*?)\])?->([a-zA-Z ]+)', file, re.M):
print(x.group(1), x.group(2), x.group(3))
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 IncomingTime
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 IncomingData
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 ThreadID
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 RequestExecuteStart
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 RequestInfo
2018.07.10 00:30:03:109 TraceID: 8HRWSI105YVO91 CheckUserInfo
2018.07.10 00:30:03:218 None Start RTS
2018.07.10 00:30:03:640 TraceID: 8HRWSI105YVO91 StartExecuteTask
2018.07.10 00:30:03:749 TraceID: 8HRWSI105YVO91 EndExecuteTask
2018.07.10 00:30:03:749 TraceID: 8HRWSI105YVO91 RequestExecuteEnd
2018.07.10 00:30:03:749 TraceID: 8HRWSI105YVO91 OutgoingData
您可以使用來只給您實際的跟蹤ID ^\[(.*?)\](?:\[TraceID: (.*?)\])?->([a-zA-Z ]+)。
- 1 回答
- 0 關注
- 276 瀏覽
添加回答
舉報