gpt4 book ai didi

javascript - 正则表达式匹配跳过第一场比赛

转载 作者:行者123 更新时间:2023-11-30 17:23:34 25 4
gpt4 key购买 nike

所以我有一个特定的日志文件:

Jul 07, 2014 12:56:06 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 07, 2014 12:56:07 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/admin] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@75443fb0]) and a value of type [java.util.WeakHashMap] (value [{class com.hp.sw.bto.security.internal.jaxb.MultiValueMapAdapter=java.lang.ref.WeakReference@53b177f5, class com.hp.sw.bto.security.internal.PrincipleImpl=java.lang.ref.WeakReference@283aa0c0, class java.util.ArrayList=java.lang.ref.WeakReference@210fb1e2, class com.hp.sw.bto.security.internal.jaxb.MultivalueMapEntry=java.lang.ref.WeakReference@d677d63, class com.hp.sw.bto.security.context.builders.SecurityContextSectionBuilder$SecurityContextSectionImpl=java.lang.ref.WeakReference@558f575, class com.hp.sw.bto.security.authz.internal.AuthzPermissionImpl=java.lang.ref.WeakReference@135ad711, class com.hp.sw.bto.security.context.builders.GroupBuilder$GroupImpl=java.lang.ref.WeakReference@30dda704, class com.hp.sw.bto.security.context.builders.RoleBuilder$RoleImpl=java.lang.ref.WeakReference@280010ac, class com.hp.sw.bto.security.internal.jaxb.MultivalueMap=java.lang.ref.WeakReference@1c46a0b8, class com.hp.sw.bto.security.internal.SecurityContextImpl=java.lang.ref.WeakReference@60e19e88}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 07, 2014 12:56:08 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/admin] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator$1] (value [com.sun.xml.bind.v2.runtime.Coordinator$1@7c6f2468]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@64bf67aa]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 07, 2014 12:56:09 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/admin] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@75443fb0]) and a value of type [java.util.WeakHashMap] (value [{class com.hp.sw.bto.security.internal.PrincipleImpl=java.lang.ref.WeakReference@522efd92, class java.util.ArrayList=java.lang.ref.WeakReference@b09a665, class com.hp.sw.bto.security.internal.jaxb.MultivalueMapEntry=java.lang.ref.WeakReference@268b368c, class com.hp.sw.bto.security.context.builders.SecurityContextSectionBuilder$SecurityContextSectionImpl=java.lang.ref.WeakReference@7daa3518, class com.hp.sw.bto.security.authz.internal.AuthzPermissionImpl=java.lang.ref.WeakReference@3183fb1c, class com.hp.sw.bto.security.context.builders.GroupBuilder$GroupImpl=java.lang.ref.WeakReference@4fdb04a9, class com.hp.sw.bto.security.context.builders.RoleBuilder$RoleImpl=java.lang.ref.WeakReference@340f1c34, class com.hp.sw.bto.security.internal.jaxb.MultivalueMap=java.lang.ref.WeakReference@4c04b49f, class com.hp.sw.bto.security.internal.SecurityContextImpl=java.lang.ref.WeakReference@48ee59b6}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 07, 2014 12:56:10 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/admin] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator$1] (value [com.sun.xml.bind.v2.runtime.Coordinator$1@7c6f2468]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@1843e122]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

我正在尝试解析它。但是,当我在测试中尝试我的正则表达式时,它工作正常并且符合我的要求。 http://regex101.com/r/sL4eR0/13但是当我在代码上尝试时,它会跳过第一个匹配项并在之后输出所有匹配项。我不太确定为什么或如何解决它。代码:http://jsfiddle.net/j7rXu/6/

最佳答案

看起来对 regex.test(localcat) 的调用正在吃掉正则表达式的第一个匹配项。如果您在循环调用 regex.exec(localcat) 之前删除此行,它应该包括循环中的第一个匹配项。

var match, regex = /^([a-zA-Z]*): (.*)(?:\s)([^co]+) ([^\s]+) (\w*)$/gm, localcat = ((reader.result).split("\n").reverse().join("\n"));

// This line eats the first match of the regex
// alert(regex.test(localcat));

while ((match = regex.exec(localcat)) !== null){
alert(match[0]);

if(match[1]==="SEVERE"){
document.getElementById("hey").innerHTML+= ("Time: " + match[3] + "<br/>");
}
}

description对于 RegExp.prototype.test() 状态:

As with exec (or in combination with it), test called multiple times on the same global regular expression instance will advance past the previous match.

关于javascript - 正则表达式匹配跳过第一场比赛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24700774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com