// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.regex.Pattern;

public class Strip {
    private static byte[] validCategories = { Character.UPPERCASE_LETTER, Character.LOWERCASE_LETTER, Character.DECIMAL_DIGIT_NUMBER };
    private static Pattern valid;
    static {
        StringBuilder sb = new StringBuilder();
        for(int c = 0; c <= 0x0000FFFF; c++) {
            for(byte cat : validCategories) {
                if(Character.getType(c) == cat) {
                    sb.append((char)c);
                }
            }
        }
        valid = Pattern.compile("[^" + Pattern.quote(sb.toString()) + "]");
    }
    public static String strip(String s) {
        return valid.matcher(s).replaceAll("");
    }
    public static void main(String[] args) {
        System.out.println(Strip.strip("a b c"));
        System.out.println(Strip.strip("123.456"));
        System.out.println(Strip.strip("æøå"));
    }
}
