正则表达式:AttributeError:' NoneType'对象没有属性' group'

时间:2018-01-31 12:55:32

标签: python regex parsing logging

我对正则表达式很陌生。

我在数据框AppEvents中有一个应用程序日志,我尝试将其分成更小的部分:

"[01/30/2018 15:01:24] [Visma.Workflow.Server.exe] Off 

                        [CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb::0] ThreadId: 12 ThreadName:  

                        Initializing of ERP client complete.    Logged from: CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb (0)



                         "

期望的输出

[01/30/2018 15:01:24], 
[App.Workflow.Server.exe] Off, [CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb::0], 
ThreadId: 12, 
ThreadName: Initializing of ERP client complete., 
Logged from: CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb (0),

我的尝试:

regex = re.compile('(.+?)\[(.+?\])] [ThreadID$ \d+] [ThreadName$
+d+]')
    res = regex.match(AppEvents.ix[2,4])
    log_parts = list(res.group())
    App_info = log_parts.pop(-1)
    App_parts = App_info.split(' ')
    log_parts.extend(App_parts)

我得到了AttributeError:' NoneType'对象没有属性' group'同时我不知道为什么。任何帮助表示赞赏!

0 个答案:

没有答案