gpt4 book ai didi

JavaRegEx 和复杂的长字符串

转载 作者:行者123 更新时间:2023-11-29 03:54:52 24 4
gpt4 key购买 nike

我正在尝试使用 Java 中的正则表达式从异常中提取值。但是字符串太复杂太长(全部在一行中):

ReturnCode={Val=9002;SubVal=9203;Text=Subscriber not found};Message=Subscriber not found;LocalizedMessage=Subscriber not found;Cause==null;StackTrace={[co.com.tigo.gatewaytigo.scp.mcommerce.method.RechargeMCommerce.getRechargeResult(RechargeMCommerce.java:72)][co.com.tigo.gatewaytigo.scp.mcommerce.MCommerceAPI.recharge(MCommerceAPI.java:353)][co.com.tigo.gatewaytigo.scp.interfacesscp.SCPFacade.recharge(SCPFacade.java:257)][co.com.tigo.gatewaytigo.webscp.ws.GatewayTigoWS.recharge(Unknown Source)][sun.reflect.GeneratedMethodAccessor4092.invoke(Unknown Source)][sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)][java.lang.reflect.Method.invoke(Method.java:597)][weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:89)][weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:71)][com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)][com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)][com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)][com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)][com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)][com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)][com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)][com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)][com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)][com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)][com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)][weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:272)][weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:185)][weblogic.wsee.jaxws.JAXWSServlet.doPost(JAXWSServlet.java:180)][javax.servlet.http.HttpServlet.service(HttpServlet.java:727)][weblogic.wsee.jaxws.JAXWSServlet.service(JAXWSServlet.java:64)][javax.servlet.http.HttpServlet.service(HttpServlet.java:820)][weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)][weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)][weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)][weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)][weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)][weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)][weblogic.security.service.SecurityManager.runAs(Unknown Source)][weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)][weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)][weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)][weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)][weblogic.work.ExecuteThread.run(ExecuteThread.java:173)]}

我想从该字符串中提取 Val 和 SubVal,我的模式是:

^(?:(?:.|\\n|\\r)*)Val=(\\d+);SubVal=(\\d+)(?:(?:.)*)$

我遇到了这个异常:

Exception in thread "main" java.lang.StackOverflowError
at java.lang.String.charAt(String.java:685)
at java.lang.Character.codePointAt(Character.java:2335)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3344)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)

我应该如何使用 Java RegEx 从该字符串中提取 Val 和 SubVal 值?

最佳答案

我看到了很多无关的比赛;为什么一个简单的 [{]Val=(\\d+);SubVal=(\\d+); 不起作用?

关于JavaRegEx 和复杂的长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6915457/

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