I take this (?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\. (?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?
regular expression from this answer. if i use this in my below program to match the url means i'm getting compiler error .
This is my code:
public static void main(String[] args) {
String url="http://justfuckinggoogleit.com/bart.gif";
matchesImageUrl(url);
}
public static void matchesImageUrl(String url){
Pattern imagePattern=Pattern.compile("(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\. (?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?");
if(imagePattern.matcher(url).matches()){
System.out.println("image matches with the pattern" + url);
}
else{
System.out.println("image does not matches with the pattern");
}
}