java中使用正则表达式

1.用正则表达式分割字符串

Pattern SPLIT2 = Pattern.compile("[,]");
String[] tmpStrings1 = SPLIT2.split(string);

2.检查字符是否存在


/** * 检查查询名称是否带.s+数字格式 * * @return true 表示带格式 * */ public static boolean checkSelectPlayerName(String name) { Pattern p = Pattern.compile(".*(\.s\d)$"); Matcher m = p.matcher(name); boolean b = m.matches(); return b; }
原文地址:https://www.cnblogs.com/zhuawang/p/4559050.html