嗨,我收到拒绝服务的通知:下一行显示常规警告

billingApplicationAcctId = billingApplicationAcctId.replaceAll(“ \” + s,“”);

您可以查看下面的代码以供进一步参考

   if (null != formatBillingAcctIdInd && formatBillingAcctIdInd.equals("Y")
                    && billingApplicationCode.equalsIgnoreCase(EPWFReferenceDataConstants.BILLING_APPICATION_ID.KENAN.name())) {
                Pattern pt = Pattern.compile("[^a-zA-Z0-9]");
                Matcher match = pt.matcher(payment.getBillingApplicationAccntId());
                while (match.find()) {
                    String s = match.group();
                    billingApplicationAcctId = billingApplicationAcctId.replaceAll("\\" + s, "");
                }
            }


我应该怎么做而不是上面的代码,所以我不会得到强化的DOS警告

最佳答案

如果您不想使用正则表达式代码,则可以按字符比较输入内容。只需更换

Pattern pt = Pattern.compile("[^a-zA-Z0-9]");
Matcher match = pt.matcher(payment.getBillingApplicationAccntId());
while (match.find()) {
    String s = match.group();
    billingApplicationAcctId = billingApplicationAcctId.replaceAll("\\" + s, "");
}


与:

String rawInput = payment.getBillingApplicationAccntId();
StringBuilder sb = new StringBuilder();
for (char c : rawInput.toCharArray()) {
    // any char that is an english letter or 0-9 is included. The rest is thrown away...
    if ((c >= 'a' && c <= 'z')
            || (c >= 'A' && c <= 'Z')
            || (c >= '0' && c <= '9')) {
        sb.append(c);
    }
}
billingApplicationAcctId = sb.toString();

10-08 16:13