res = res.replaceAll("[^\\\\]\\$"+type, "\\$");
res = res.replaceAll("([^\\\\])\\$"+type, "$1\\$");
        private String applyTypeRule(String rule, String type, String ruleType, Matcher m) {            String res = rule == null ? "$"+ruleType+"0" : rule;            for (int i = 0; i < TYPES.length; i++) {                if (TYPES[i].equals(type)) {                    res = res.replaceAll("[^\\\\]\\$"+type, "\\$");                    res = res.replaceAll("^\\$"+type, "\\$");                } else {                    res = res.replaceAll("[^\\\\]\\$"+TYPES[i], "\\\\\\$"+TYPES[i]);                    res = res.replaceAll("^\\$"+TYPES[i], "\\\\\\$"+TYPES[i]);                }            }                        StringBuffer sb = new StringBuffer();            m.reset();            m.find();            m.appendReplacement(sb, res);            return sb.toString();        }