java cut file extension from url

I need to cut file extension from urls like this:

So I want to get ‘svg’ and ‘eot’.
Im doing it like this(note that I want to avoid all spec chars not only “#”):

 String extension = path.substring(path.lastIndexOf(".") + 1) ;   //cut after dot path
     extension = extension.replaceAll("[^A-Za-z0-9]", ";");   // replace all special character on ";"

        if(extension.indexOf(";") > 0) {
            extension = extension.substring(0, extension.indexOf(";")); // cut extension before first spec. char

But maybe I can do it faster?

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.