在常规蚂蚁风格外卡路径字符串匹配

问题描述 投票:0回答:1

下面是场景:

情况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
1个回答
1
投票

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)
© www.soinside.com 2019 - 2024. All rights reserved.