Reputation: 21
I'm trying to check if a string ends with a point and 2 or 3 characters. The regex I use is:
[.][a-z0-9A-Z][a-z0-9A-Z][a-z0-9A-Z]$
String example: qsdgfdssdh.nfo
It should return true but it always returns false.
Can you help me?
Thanks
Upvotes: 1
Views: 43
Reputation: 522762
The String#matches
function applies the pattern to the entire string. So the following should work:
String input = "qsdgfdssdh.nfo";
if (input.matches(".*\\.[0-9A-Za-z]{3}")) {
System.out.println("match");
}
If you're wondering what your current pattern would match with String#matches
, it would match .nfo
:
String input = ".nfo";
if (input.matches("\\.[0-9A-Za-z]{3}")) {
System.out.println("match");
}
Upvotes: 1