例如在mysql數據庫中建表時表名不能使用特殊符號,‘-’,‘{}’等等,所以我們要篩選去掉
public static void main(String[] args) { String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?-]"; String str = "dKdcfe_2018年軟件基地年報1、(130000)-20190806102546_20211103"; String newString = str.replaceAll(regEx, "");//不想保留原來的字符串可以直接寫成 “str = System.out.println(newString); }
篩選完后: