Java tutorial
//package com.java2s; /** * Copyright (c) 2012 Todoroo Inc * * See the file "LICENSE" for the full license governing this code. */ public class Main { /** * Returns the final word characters after the last '.' */ public static String getFileExtension(String file) { int index = file.lastIndexOf('.'); String extension = ""; if (index > 0) { extension = file.substring(index + 1); if (!extension.matches("\\w+")) { extension = ""; } } return extension; } }