Reputation: 743
I have the following regular expression (?s)^(?<=.*Exception.*)<The server started in RUNNING mode.>
, so basically I want to find any Exception
that was thrown before the server starts running.
I have a test log file that is supposed to match the given regular expression but does not match. How I match is that I read the whole log file into a string and the apply the regex on this string.
Is there something I am missing on this regular expression?
Example input:
Should Match
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.>
Should not match
<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)
.
.
.
Upvotes: 0
Views: 202
Reputation: 1639
Lookaheads and lookbehinds are both zero-width. However one is allowed a regular expression inside a lookahead, but not in a lookbehind (at least, not unless it is a fixed-length regexp). The reason for this is simply that most regexp engines are not designed to apply regexps backward.
In fact there are exceptions to this rule, and some engines will support the OP's regexp. However, unless you are using one of these exceptional regexp engines, then you cannot have a variable length regexp (i.e. a regexp that can match a variable length substring) in your lookbehind, which is the problem with the OP's original regexp.
A good explanation of lookaround can be found at http://www.regular-expressions.info/lookaround.html
You can solve the problem without using a lookbehind. Try this expression:
(\w+Exception).*<The server started in RUNNING mode.>
This matches if an exception happened before the servers started in RUNNING mode, and also captures the first such exception in a group. If all you want to do is ascertain that an exception occurred, you could drop the round brackets.
Upvotes: 1
Reputation: 11116
Lookbehinds need to be zero-width, thus quantifiers are not allowed.
better remove the .*
(?s)(?<=Exception)<The server started in RUNNING mode.>
Suppose you want to capture all the exceptions in the log
use this :
[\w]+Exception
there is no need of using lookaheads or lookbehinds.
update:
If you are only concerned to know if the server started with exception or not I guess this will do it for you:
(Exception[\s\S]*?The server started in RUNNING mode)
you will get a match in the previous string but not in the second one.
Upvotes: 2