Java tutorial
//package com.java2s; //License from project: Apache License import java.util.regex.Pattern; public class Main { private static final Pattern invalidXml10 = Pattern .compile("[^\u0009\n\r\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]"); /** * The pattern matching does not work. * * @param sequence the character sequence * @return sanitized string */ public static String sanitizeXml10(CharSequence sequence) { if (sequence == null) { return null; } if (sequence.length() == 0) { return ""; } return invalidXml10.matcher(sequence).replaceAll("\uFFFD"); } public static String sanitizeXml10(char[] sequence, int offset, int length) { return sanitizeXml10(new String(sequence, offset, length)); } }