Java tutorial
//package com.java2s; public class Main { /** * Replaces all dots in a filename with underscores except the last one. * * @param filename * filename to sanitize * @return string with a single dot only */ public static String forceSingleExtension(final String filename) { return filename.replaceAll("\\.(?![^.]+$)", "_"); } }