From 576b239a8c03b3e7c78171c0810d9492ff209375 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 19 Nov 2012 07:02:49 +0000 Subject: [PATCH] * match(): auto-select group 1 if there is one; support named groups --- .../sourceforge/filebot/format/ExpressionFormat.lib.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy index 385d0e89..24e09b72 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy @@ -41,10 +41,10 @@ String.metaClass.pad = Number.metaClass.pad = { length = 2, padding = "0" -> del /** * Return a substring matching the given pattern or break. */ -String.metaClass.match = { String pattern, int matchGroup = 0 -> +String.metaClass.match = { String pattern, matchGroup = null -> def matcher = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(delegate) if (matcher.find()) - return matcher.group(matchGroup) + return matcher.groupCount() > 0 && matchGroup == null ? matcher.group(1) : matcher.group(matchGroup ?: 0) else throw new Exception("Match failed") }