Java tutorial
//package com.java2s; public class Main { /** * Generates valid component id from component name (see general comments in * class {@link ComponentIDUtil}) * * @param compName * @return */ public static String generateIDFromName(String compName) { String alphaDigitsUnderscoreDashString = compName.replaceAll("[^a-zA-Z0-9\\-\\_]+", "_"); if (alphaDigitsUnderscoreDashString.matches("^[0-9].*")) { alphaDigitsUnderscoreDashString = "_" + alphaDigitsUnderscoreDashString; } return alphaDigitsUnderscoreDashString; } }