Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String getSanitizedName(final String fileName) { return fileName.replaceAll("[^\\w]", "_").replaceAll("[_]{2,}", "_"); } }