From d76b74b13f910fe16fdfe08e02aa9e9dd03f4770 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 3 Apr 2016 03:30:29 +0000 Subject: [PATCH] String.matchAll() should work like String.match() --- source/net/filebot/format/ExpressionFormatMethods.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/format/ExpressionFormatMethods.java b/source/net/filebot/format/ExpressionFormatMethods.java index 4a8591f6..1e467a50 100644 --- a/source/net/filebot/format/ExpressionFormatMethods.java +++ b/source/net/filebot/format/ExpressionFormatMethods.java @@ -72,7 +72,7 @@ public class ExpressionFormatMethods { public static String match(String self, String pattern, int matchGroup) throws Exception { Matcher matcher = compile(pattern, CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS | MULTILINE).matcher(self); if (matcher.find()) { - return (matcher.groupCount() > 0 && matchGroup < 0 ? matcher.group(1) : matcher.group(matchGroup < 0 ? 0 : matchGroup)).trim(); + return matcher.group(matchGroup < 0 ? matcher.groupCount() > 0 ? 1 : 0 : matchGroup).trim(); } else { throw new Exception("Pattern not found"); } @@ -82,14 +82,14 @@ public class ExpressionFormatMethods { * Return a list of all matching patterns or break. */ public static List matchAll(String self, String pattern) throws Exception { - return matchAll(self, pattern, 0); + return matchAll(self, pattern, -1); } public static List matchAll(String self, String pattern, int matchGroup) throws Exception { List matches = new ArrayList(); Matcher matcher = compile(pattern, CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS | MULTILINE).matcher(self); while (matcher.find()) { - matches.add(matcher.group(matchGroup).trim()); + matches.add(matcher.group(matchGroup < 0 ? matcher.groupCount() > 0 ? 1 : 0 : matchGroup).trim()); } if (matches.size() > 0) {