is string an Image Url - Java java.util.regex

Java examples for java.util.regex:Match URL

Description

is string an Image Url

Demo Code

import java.util.regex.Pattern;

public class Main {

  public static void main(String[] argv) {
    String url = "http://java2s.com";
    System.out.println(isImgUrl(url));
  }/* w  w w  . j  av  a 2s  . c o m*/

  private final static Pattern IMG_URL = Pattern.compile(".*?(gif|jpeg|png|jpg|bmp)");

  public static boolean isImgUrl(String url) {
    return !isEmpty(url) && IMG_URL.matcher(url).matches();
  }

  public static boolean isEmpty(String str) {
    return str == null || str.trim().length() == 0 || str.trim().equalsIgnoreCase("null");
  }

}

Related Tutorials