下面是场景:
情况(1):
String patternStr = "hello/*"
// This is the pattern supplied
String s1 = "hello/text"
String s2 = "hello/text/abcd"
我需要比较上述字符串 s1,s2 ...与patternStr 在以上两种情况下,我应该得到正确的结果。因为我不担心路径的深度。
案例(2):
String patternStr = "hello/"
In this case, In the above two strings s1 only should match As the pattern is used to match with in the hello.
请建议我一种更好的方式来检查常规而不使用 常规表达式。
答案 0 :(得分:1)
Groovy捆绑了Ant,因此您可以使用ant的matcher:
import org.apache.tools.ant.types.selectors.SelectorUtils
String patternStr = "hello/*"
String s1 = "hello/text"
String s2 = "hello/text/abcd"
assert SelectorUtils.match(patternStr, s1)
assert SelectorUtils.match(patternStr, s2)