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) {