parent
8fba11dd74
commit
49d0ced16c
|
@ -71,6 +71,9 @@ public class Regex {
|
|||
int nextIndex = pattern.indexOf('*', firstIndex + 1);
|
||||
if (nextIndex == -1) {
|
||||
return str.endsWith(pattern.substring(1));
|
||||
} else if (nextIndex == 1) {
|
||||
// Double wildcard "**" - skipping the first "*"
|
||||
return simpleMatch(pattern.substring(1), str);
|
||||
}
|
||||
String part = pattern.substring(1, nextIndex);
|
||||
int partIndex = str.indexOf(part);
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Random;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class RegexTests extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
|
@ -53,4 +54,18 @@ public class RegexTests extends ElasticsearchTestCase {
|
|||
Pattern.compile("\\w\\d{1,2}", current); // accepts the flags?
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 1000)
|
||||
public void testDoubleWildcardMatch() {
|
||||
assertTrue(Regex.simpleMatch("ddd", "ddd"));
|
||||
assertTrue(Regex.simpleMatch("d*d*d", "dadd"));
|
||||
assertTrue(Regex.simpleMatch("**ddd", "dddd"));
|
||||
assertFalse(Regex.simpleMatch("**ddd", "fff"));
|
||||
assertTrue(Regex.simpleMatch("fff*ddd", "fffabcddd"));
|
||||
assertTrue(Regex.simpleMatch("fff**ddd", "fffabcddd"));
|
||||
assertFalse(Regex.simpleMatch("fff**ddd", "fffabcdd"));
|
||||
assertTrue(Regex.simpleMatch("fff*******ddd", "fffabcddd"));
|
||||
assertFalse(Regex.simpleMatch("fff******ddd", "fffabcdd"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue