我有以下正则表达式(?s)^(?<=.*Exception.*)<The server started in RUNNING mode.>
,所以基本上我想找到在服务器开始运行之前抛出的任何Exception
。
我有一个测试日志文件,该文件应该与给定的正则表达式匹配但不匹配。我如何匹配是我将整个日志文件读入一个字符串并将正则表达式应用于此字符串。
这个正则表达式上有什么我缺少的东西吗?
示例输入:
应该匹配
Sep 25, 2014 9:17:28 AM za.co.hide.health.common.cache.impl.ReadAccessorImpl initializeCache
INFO: Finished Caching cache.name.treatment.protocol.limit.period: 7 items cached
Sep 25, 2014 9:17:29 AM org.springframework.cache.ehcache.EhCacheManagerFactoryBean destroy
INFO: Shutting down EhCache CacheManager
Sep 25, 2014 9:17:29 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [hide.health.clinicalsystem.bcl.treatmentProtocolService]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hide.health.clinicalsystem.bcl.treatmentProtocolService' defined in URL [file:/J:/Oracle/Middleware/Oracle_Home/user_projects/domains/AUTH/servers/AUTH_SER/tmp/_WL_user/treatment_protocol_deployment_ear/fctudi/APP-INF/classes/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocol' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'treatmentProtocolActivationDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocolActivationDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'treatmentProtocolDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocolDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'protocolStagesDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'protocolStagesDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:387)
at org.springframework.web.context.ContextLoader.loadParentContext(ContextLoader.java:559)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:303)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:661)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:241)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:198)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:183)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1783)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2807)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:822)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258)
at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:61)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:222)
at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:414)
at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)
at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200)
at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)
at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:191)
at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:99)
at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
.
.
.
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.22.9.37:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on fe80:0:0:0:688a:1e43:b337:a3b:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Warning> <Server> <BEA-002611> <The hostname "DHTBMS02.hide.holdings.co.za", maps to multiple IP addresses: 172.22.9.37, fe80:0:0:0:688a:1e43:b337:a3b%12.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on fe80:0:0:0:0:100:7f:fffe:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[4]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[5]" is now listening on 0:0:0:0:0:0:0:1:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on fe80:0:0:0:0:5efe:ac16:925:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000331> <Started the WebLogic Server Administration Server "AUTH_SER" for domain "AUTH" running in development mode.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
不匹配
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
<Sep 25, 2014 9:17:30 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.22.9.37:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on fe80:0:0:0:688a:1e43:b337:a3b:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Warning> <Server> <BEA-002611> <The hostname "DHTBMS02.hide.holdings.co.za", maps to multiple IP addresses: 172.22.9.37, fe80:0:0:0:688a:1e43:b337:a3b%12.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on fe80:0:0:0:0:100:7f:fffe:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[4]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[5]" is now listening on 0:0:0:0:0:0:0:1:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on fe80:0:0:0:0:5efe:ac16:925:7001 for protocols iiop, t3, ldap, snmp, http.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000331> <Started the WebLogic Server Administration Server "AUTH_SER" for domain "AUTH" running in development mode.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
<Sep 25, 2014 9:17:31 AM CAT> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
Sep 25, 2014 9:17:28 AM za.co.hide.health.common.cache.impl.ReadAccessorImpl initializeCache
INFO: Finished Caching cache.name.treatment.protocol.limit.period: 7 items cached
Sep 25, 2014 9:17:29 AM org.springframework.cache.ehcache.EhCacheManagerFactoryBean destroy
INFO: Shutting down EhCache CacheManager
Sep 25, 2014 9:17:29 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [hide.health.clinicalsystem.bcl.treatmentProtocolService]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hide.health.clinicalsystem.bcl.treatmentProtocolService' defined in URL [file:/J:/Oracle/Middleware/Oracle_Home/user_projects/domains/AUTH/servers/AUTH_SER/tmp/_WL_user/treatment_protocol_deployment_ear/fctudi/APP-INF/classes/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocol' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'treatmentProtocolActivationDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocolActivationDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'treatmentProtocolDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treatmentProtocolDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Cannot resolve reference to bean 'protocolStagesDTOBuilder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'protocolStagesDTOBuilder' defined in class path resource [spring/treatment-protocol-core-context.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:387)
at org.springframework.web.context.ContextLoader.loadParentContext(ContextLoader.java:559)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:303)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:661)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:241)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:198)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:183)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1783)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2807)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:822)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258)
at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:61)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:222)
at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:414)
at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)
at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200)
at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)
at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:191)
at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:99)
at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
.
.
.
答案 0 :(得分:2)
Lookbehinds需要为零宽度,因此不允许使用量词。
更好地删除.*
(?s)(?<=Exception)<The server started in RUNNING mode.>
假设您要捕获日志中的所有异常
使用它:
[\w]+Exception
不需要使用前瞻或外观。
更新
如果你只是想知道服务器是否以异常启动,我想这会为你做:
(Exception[\s\S]*?The server started in RUNNING mode)
您将在上一个字符串中获得匹配,但不会在第二个字符串中获得匹配。
答案 1 :(得分:1)
Lookaheads和lookbehinds 都零宽度。然而,在前瞻中允许一个正则表达式,但不允许在后面看(至少,除非它是固定长度的正则表达式)。原因很简单,大多数正则表达式引擎都不是为了向后应用regexp而设计的。
实际上这个规则有例外,有些引擎会支持OP的regexp。但是,除非你使用这些特殊的regexp引擎之一,否则你的lookbehind中不能有一个可变长度regexp(即可以匹配可变长度子字符串的正则表达式),这是OP原始正则表达式的问题。
可以在http://www.regular-expressions.info/lookaround.html
找到有关环视的详细说明您可以在不使用lookbehind的情况下解决问题。试试这个表达式:
(\w+Exception).*<The server started in RUNNING mode.>
如果在RUNNING模式下服务器启动之前发生异常,则匹配,并且还捕获组中的第一个此类异常。如果您只想确定发生了异常,则可以删除圆括号。