Java Regex look-behinds

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)
    .
    .
    .

Answers


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.


Need Your Help

How do I pass the # symbol as part of a GET querystring in the URL?

javascript jquery ajax get query-string

I am using javascript (using jquery) to pass a # symbol as a GET parameter via AJAX call.

Fragment shader output not affected by rotations

c++ opengl fragment-shader vertex-shader

I'm writing a shader that should implement the Phong lighting model. The problem is that I am not using glRotatef and these functions, instead I am passing a scale and translate vector, and a rotat...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.