正则例子

1. 判断字符串是否由字母、数字、空格组成

Boolean isNo = "abc".matches("^[a-z0-9A-Z\s]+$")

2. 判断字符串是否包含浮点数+”未支付“

Boolean isNo = Pattern.compile("\d+\.{0,1}\d+未支付").matcher(financeInfo).find();

3. 字符串格式为 00000或者00000-0000

Boolean isNo = "abc".matches("^([a-z0-9A-Z]{5})(-[a-z0-9A-Z]{4})?$"

4. 替换特殊字符

String regEx = "[
`~!@#$¿¡%^&*()+=|{}':;',\\<>/?~!@#¥%……&*()——+|【】‘;:”“’"。,、?]";
String string1 = chars.replaceAll(regEx, "");
原文地址:https://www.cnblogs.com/yifanSJ/p/13065259.html