public static String escapeTitle ( final String title ) { final String escapedTitle = title . replaceAll ( "^[^" + UNICODE_TITLE_START_CHAR + "]*" , "" ) . replaceAll ( "[^" + UNICODE_WORD + ". -]" , "" ) ; if ( isNullOrEmpty ( escapedTitle ) ) { return "" ; } else { // Remove whitespace return escapedTitle . replaceAll ( "\\s+" , "_" ) . replaceAll ( "(^_+)|(_+$)" , "" ) . replaceAll ( "__" , "_" ) ; } }
Escapes a title so that it is alphanumeric or has a fullstop underscore or hyphen only . It also removes anything from the front of the title that isn t alphanumeric .