优化正则表达式以覆盖匹配范围

时间:2019-07-03 17:50:33

标签: java regex regex-group regex-greedy

我最近实现了Java方法签名Regex ...

我能够匹配大多数名称空间,但是一旦我增加了测试范围,它就开始无法匹配

我需要帮助来调整表情以匹配下面列出的情况


Pattern  METHOD_PATTERN = Pattern
      .compile("^((((([a-zA-Z_$][a-zA-Z\\\\d_$]*\\.)*[a-zA-Z_$][a-zA-Z\\\\d_$]*)\\.([a-zA-Z_$][a-zA-Z\\\\d_$]*))\\.(<?[a-zA-Z_$][a-zA-Z\\\\d_$]*>?))\\.(<?[a-zA-Z_$][a-zA-Z\\\\d_$]*>?))+\\s*:\\s*(\\((.*)\\).+)");

//Test methods to match expression to 

// successfully matches pattern
java.util.TimeZone.getTimeZone : (Ljava.lang.String;)Ljava.util.TimeZone;

//fails to match pattern
org.apache.coyote.http2.Stream$StreamInputBuffer.doRead : (Lorg.apache.tomcat.util.net.ApplicationBufferHandler;)I, 
org.apache.coyote.http2.Stream$StreamOutputBuffer.end : ()V, 
org.apache.coyote.http2.Http2UpgradeHandler.startRequestBodyFrame : (II)Ljava.nio.ByteBuffer;, 
org.apache.coyote.http2.StreamProcessor.process : (Lorg.apache.tomcat.util.net.SocketEvent;)V, 
org.apache.coyote.http2.Stream.reserveWindowSize : (IZ)I, 
org.apache.coyote.http2.Http2UpgradeHandler.reprioritise : (IIZI)V, 
org.apache.coyote.http2.Stream.close : (Lorg.apache.coyote.http2.Http2Exception;)V, 
org.apache.coyote.http2.Http2UpgradeHandler.upgradeDispatch : (Lorg.apache.tomcat.util.net.SocketEvent;)Lorg.apache.tomcat.util.net.AbstractEndpoint$Handler$SocketState;, 
org.apache.coyote.http2.Http2UpgradeHandler.writeBody : (Lorg.apache.coyote.http2.Stream;Ljava.nio.ByteBuffer;IZ)V, 
org.apache.coyote.http2.Http2UpgradeHandler.setting : (Lorg.apache.coyote.http2.Setting;J)V, 
org.apache.coyote.http2.Http2UpgradeHandler.pingReceive : ([BZ)V


在调整表达式以扩大匹配范围方面会提供帮助

0 个答案:

没有答案