正则表达式专项练习

//匹配所有非英文字符
String input = "$bo*y gi!r#l"; String mode = "[^a-zA-Z]";//注意亦或的符号在中括号里面 Pattern pattern = Pattern.compile(mode); String newStr = pattern.matcher(input).replaceAll(" ");//把非英文字符替换为空格 String string = "AAAA BBBB"; String test = string.replaceAll("\\s+", " ");//多个空格 替换为一个空格
     
        String ipAddress = "1.2.3.4";
// String[] arrays = ipAddress.split(".");
String[] arrays = ipAddress.split("\\.");//注意 这里的点必须使用正则表达式方式
原文地址:https://www.cnblogs.com/juniorMa/p/15744871.html