if (filename.length() >= startLength + digits + endLength
&& filename.startsWith(base + templateStart)
&& filename.endsWith(templateEnd)
- && numString.matches("[0-9]*"))
+ // match exactly digits number of number-characters (numString
+ // should be all digits and at least the right length), or more than
+ // digits long with proviso it's not zero-leading.
+ && (numString.matches("[0-9]{" + digits + "}")
+ || numString.matches("[1-9][0-9]{" + digits + ",}")))
{
this.base = extensionMatch ? savedFilename + base : base;
this.templateStart = templateStart;