我有以下正则表达式:
(?<time>[^ ]* [^ ]* ) (?<class>[^ ]+) *(?<level>[^ ]+)[ -]+(?<message>.*)
尝试匹配java堆栈跟踪,其示例为:
2015-01-28 18:48:33,484 grails.plugin.jms.JmsGrailsPlugin INFO - registering listener for 'sendPostLinkByEmailToUnbindedContacts' of service 'postCreatedActivityListener' to TOPIC 'post.created'
2015-01-28 18:48:35,569 sf.ehcache.config.ConfigurationFactory WARN - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/var/lib/tomcat7/webapps/ws/WEB-INF/lib/ehcache-core-2.4.8.jar!/ehcache-failsafe.xml
2015-01-28 18:48:37,809 proxy.pojo.javassist.JavassistLazyInitializer ERROR - HHH000142: Javassist Enhancement failed: hibe.core.communication.feed.Post
java.lang.RuntimeException: duplicate method: attach in hibe.core.communication.feed.Post_$$_javassist_64
at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:509)
at ...
请参阅Rubular Link了解我的正则表达式和更完整的输入样本。
我的正则表达式正常,但message
组除外,它与整个消息不匹配:我需要让message
组包含整个堆栈跟踪直到下一个。知道下一个是否是这种格式的日期的模式:2015-01-28 18:48:33,484
可行吗?
答案 0 :(得分:1)
使用:
*?
,因此匹配不会消耗到最后一个日期戳的所有输入像这样:
(?<time>[^ ]* [^ ]* ) (?<class>[^ ]+) *(?<level>[^ ]+)[ -]+(?<message>.*?(?=\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d{3}))
请参阅demo