简体   繁体   中英

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

The child is org.jboss.modules.ModuleClassLoader@692578be and its parent is 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

In above the child is sun.misc.Launcher$AppClassLoader@62c8aeb3 and the parent is sun.misc.Launcher$ExtClassLoader@65459c6f

I have this regular expression .* (.*) 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

but instead it should: sun.misc.Launcher$AppClassLoader@62c8aeb3

You can use this regex:

(\S+) parents?: ([^,]+)

Working Demo

正则表达式默认是贪婪的,您应该告诉它排除,

.* (.*) parents?: ([^,]*),?.*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM