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 w  w  .  j a v a2 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;
    }
}

Related Exercise