diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy index ecc90b8e..b8b3e676 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy @@ -24,6 +24,12 @@ Number.metaClass.compareTo = { String other -> delegate.toString().compareTo(oth String.metaClass.pad = Number.metaClass.pad = { length = 2, padding = "0" -> delegate.toString().padLeft(length, padding) } +/** + * Return a substring matching the given pattern or break. + */ +String.metaClass.match = { def matcher = delegate =~ it; if (matcher.find()) return matcher[0] else throw new Exception("Match failed") } + + /** * Use empty string as default replacement. */ @@ -54,12 +60,6 @@ String.metaClass.upperInitial = { replaceAll(/\b[a-z]/, { it.toUpperCase() }) } String.metaClass.lowerTrail = { replaceAll(/\b(\p{Alpha})(\p{Alpha}+)\b/, { match, initial, trail -> initial + trail.toLowerCase() }) } -/** - * Return a substring matching the given pattern or nothing at all. - */ -String.metaClass.match = { def matcher = delegate =~ it; matcher.find() ? matcher[0] : "" } - - /** * Return substring before the given pattern. */ diff --git a/website/naming.html b/website/naming.html index 8be9f745..58128e22 100644 --- a/website/naming.html +++ b/website/naming.html @@ -274,7 +274,7 @@ pad(length, padding = "0")Pad strings or numbers with given characters ('0' by default).

- replaceAll(pattern, replacement = "")Replace or remove all occurrences of the pattern. + match(pattern)Get a substring matching the given pattern or break.

space(replacement)Replace all spaces (e.g. "Doctor Who" -> "Doctor_Who"). @@ -286,15 +286,15 @@ lowerTrail()Lower-case all letters that are not initials (e.g. "Gundam SEED" -> "Gundam Seed").

- match(pattern)Get a substring matching the given pattern or nothing at all. + before(pattern)Get the substring before the given pattern or the original value.

- before(pattern)Get the substring before the given pattern or the original value. -

-

after(pattern)Get the substring after the given pattern or the original value.

+ replaceAll(pattern, replacement = "")Replace or remove all occurrences of the pattern. +

+

replaceTrailingBrackets(replacement = "")Replace trailing parenthesis including any leading whitespace (e.g. "The IT Crowd (UK)" -> "The IT Crowd").