-
java:只保留中文,字母,数字,横线,下划线和各种中英文标点符号
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static void main(String[] args) {
String str = "#¥%**&测试erwfs14124124&*(*>>——测试";
String regexStr = str.replaceAll("[\t\n\r]", "").trim();
String regex = "[^\u4E00-\u9FA5a-zA-Z0-9\\-\\-_—.,;'\"!?。,;!?‘’“” ]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(regexStr);
String matcherStr = matcher.replaceAll("");
System.out.println(matcherStr);
}
输出结果:测试erwfs14124124——测试
-
常用的java正则表达式( 通过 Java常用正则表达式_正则表达式0到9_欧尼熊不懂的博客-CSDN博客)
-
vue: 只保留中文,字母,数字,横线,下划线和各种中英文标点符号
const value = '#¥%**&测试erwfs14124124&*(*>>——测试';
const newValue = this.note = value.trim().replace(/[^[\u4E00-\u9FA5a-zA-Z0-9\-\-_—.,;'\"!?。,;!?‘’“” ]/g, "");
console.log(newValue);
输出结果:测试erwfs14124124——测试