[英]Ignore strings after character if character found
I need to have regex which finds the child and parent. 我需要有找到孩子和父母的正则表达式。 For example: 例如:
-->2014-05-21 22:05:23.092 INFO [Core] org.jboss.modules.ModuleClassLoader@692578be parents: sun.misc.Launcher$AppClassLoader@62c8aeb3, sun.misc.Launcher$ExtClassLoader@65459c6f -> 2014-05-21 22:05:23.092信息[核心] org.jboss.modules.ModuleClassLoader@692578父母:sun.misc.Launcher$AppClassLoader@62c8aeb3,sun.misc.Launcher$ExtClassLoader@65459c6f
The child is org.jboss.modules.ModuleClassLoader@692578be
and its parent is sun.misc.Launcher$AppClassLoader@62c8aeb3
. 子节点是org.jboss.modules.ModuleClassLoader@692578be
,其父节点是sun.misc.Launcher$AppClassLoader@62c8aeb3
。 The later string after ,
is ignored. 后来的串后,
被忽略。
-->2014-05-21 22:04:34.118 INFO [Core] sun.misc.Launcher$AppClassLoader@62c8aeb3 parent: sun.misc.Launcher$ExtClassLoader@65459c6f -> 2014-05-21 22:04:34.118信息[核心] sun.misc.Launcher$AppClassLoader@62c8aeb3父级:sun.misc.Launcher$ExtClassLoader@65459c6f
In above the child is sun.misc.Launcher$AppClassLoader@62c8aeb3
and the parent is sun.misc.Launcher$ExtClassLoader@65459c6f
在上面的子级是sun.misc.Launcher$AppClassLoader@62c8aeb3
,父级是sun.misc.Launcher$ExtClassLoader@65459c6f
I have this regular expression .* (.*) parents?: (.*),?.*
. 我有这个正则表达式.* (.*) parents?: (.*),?.*
。 It works with the second example. 它适用于第二个示例。 But for the first one outputs parent as: 但是对于第一个输出,父级为:
sun.misc.Launcher$AppClassLoader@62c8aeb3, sun.misc.Launcher$ExtClassLoader@65459c6f sun.misc.Launcher $ AppClassLoader @ 62c8aeb3,sun.misc.Launcher $ ExtClassLoader @ 65459c6f
but instead it should: sun.misc.Launcher$AppClassLoader@62c8aeb3
但应该改为: sun.misc.Launcher$AppClassLoader@62c8aeb3
正则表达式默认是贪婪的,您应该告诉它排除,
:
.* (.*) parents?: ([^,]*),?.*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.