下面是场景:
情况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.
请给我建议的更好的方式来在常规使用了正则表达式来检查。
Groovy中带有蚂蚁捆绑在一起,所以你可以只使用ant的匹配:
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)