正则过滤(简单举例)
String testString = "123$";
String regEx = "\\$";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(testString);
System.out.println(m.replaceAll("").trim());
处理特殊字符
String testString = "123$";
String regEx="[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(testString);
System.out.println(m.replaceAll("").trim());
package com.hollysys.hollitcmc.service.station.impl;
import com.hollysys.hollitcmc.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
import java.util.List;
public class Test {
public static void main(String[] args) {
String str = "10.30.1.62_21000:RBC:30:100";
String split = "\\pP|\\pS|\\pZ";
List<String> list = Arrays.asList(str.split(split));
System.out.println(list);
String strAlarmContent = "%1,1526";
String strAlarmContent2 = strAlarmContent.replaceAll("%1", "0");
System.out.println(strAlarmContent2);
}
}