I had requirement where user should add only specific type of links
as part of the attachments. For example, if user wants to upload
file of type pdf, the url should end with .pdf similarly for document
it should be .doc
To check this scenario I had written JUnit test as below
String url="ar.jpg";
String pm="(.*?)\\.(jpg|jpeg|png|gif)$";
Pattern p = Pattern.compile("pm");
Matcher m = p.matcher(url);
System.out.println("-----exp "+m.matches());
This test is always returning false.
Is there something wrong
with my Pattern.
You have a misprint – “pm” string is passed to compile() method, but pm variable must be passed: