JUnit test for specific file restricts giving false output
I had requirement where user should add only specific type of links as part o开发者_如何学运维f 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:
String pm="(.*?)\\.(jpg|jpeg|png|gif)$";
Pattern p = Pattern.compile(pm); // <- here
精彩评论