1、处理前
">13123%&*(^%$$$213131331
2、处理后
13123213131331
3、验证
String str = "\">13123%&*(^%$$$213131331";
System.out.println(str);
System.out.println(RemoveSpecialCharacters(str));
4、处理方法
/** 空字符串 */
private static final String NULLSTR = "";
/**
* 去除特殊字符串
*
* @param param
* String
* @return String 处理后的字符串
*/
public static String RemoveSpecialCharacters(String param) {
if (isEmpty(param)) {
return NULLSTR;
}
String regEx = "[`~!@#$%^&*()\\-+={}':;,\\[\\].<>/?¥%…()_+|【】‘;:”“\"\"’。,、?\\s]";
Pattern patter = Pattern.compile(regEx);
String result = patter.matcher(param).replaceAll("");
return result;
}
/**
* * 判断一个对象是否为空
*
* @param object
* Object
* @return true:为空 false:非空
*/
public static boolean isNull(Object object) {
return object == null;
}
/**
* * 判断一个字符串是否为空串
*
* @param str
* String
* @return true:为空 false:非空
*/
public static boolean isEmpty(String str) {
return isNull(str) || NULLSTR.equals(str.trim());
}