Je prends cette (?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\. (?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?
expression régulière à partir de ce answer. si je l'utilise dans mon programme ci-dessous pour correspondre à l'URL signifie que je reçois erreur du compilateur.Correspondance URL avec l'expression rationnelle
Ceci est mon 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");
}
}
Je donnerais 10 pour le lien dans votre ideone, si je pouvais: P – Perception