Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void isMatch(String regex, String product)
- {
- try {
- System.out.println("regex(" + regex + ") product(" + product + ")");
- Pattern pattern = Pattern.compile(regex.toLowerCase());
- Matcher matcher = pattern.matcher(product.toLowerCase());
- System.out.println(matcher.matches() ? "truen" : "falsen");
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- public static void main(String[] args)
- {
- // true ?!
- isMatch("a*.*/REGEX", "a1.0/REGEX");
- isMatch("/*.*/REGEX", "/1.0/REGEX");
- isMatch("/*.*/REGEX", "/abc/REGEX");
- // Exception as expected
- isMatch("*.*/REGEX", "1.0/REGEX");
- }
- ## Why are these cases working?
- regex(a*.*/REGEX) product(a1.0/REGEX)
- true
- regex(/*.*/REGEX) product(/1.0/REGEX)
- true
- regex(/*.*/REGEX) product(/abc/REGEX)
- true
- ## This is what I expected to happened
- regex(*.*/REGEX) product(1.0/REGEX)
- java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
- *.*/regex
- ^
Add Comment
Please, Sign In to add comment