Matches
returns true
the specified regular expression matches the entire target string. It won't return true
if the expression only matches part of the string. So to use matches
, you want to supply an expression that matches the whole filename. In your case, that would be:
return filename.matches(".*\\.ack\\.gz"); returns false
The .*
at the front of the expression matches anything at the front of the string that isn't matched by the rest of the expression, so that the expression will match the entire target string.
You don't need the $
because the expression already has to match to the end of the string, and so it's redundant.