Java - Write code to get Http File Extension via regex

Requirements

Write code to get Http File Extension via regex

Demo

//package com.book2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) {
        String imgName = "book2s.com";
        System.out.println(getHttpFileExt(imgName));
    }/*from  w  ww  .  j a v  a 2 s  .  c  om*/

    public static String getHttpFileExt(String imgName) {
        String str = "";
        String p = "(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP).*$";
        Pattern pattern = Pattern.compile(p);
        Matcher matcher = pattern.matcher(imgName);
        if (matcher.find()) {
            str = matcher.group();
        }
        return str;
    }
}