java常用API
package com.orcal.demc01; public class Regex2 { public static void main(String[] args) { // TODO Auto-generated method stub //将符合规则的字符串内容,全部替换为新字符串 //将a替换成b String str="java ai wo,wo ai java"; String regex="a"; String s=str.replaceAll(regex, "b"); System.out.println(s); // 匹配合法的邮箱 //+是出现一次或多次 String regex1="[a-zA-Z0-9]+@[a-zA-z0-9]+\\.[a-zA-Z]+"; String str1="1051765559@qq.com"; boolean f=str1.matches(regex1); System.out.println(f); String regex2=".+"; String str2="1051765559@qq.com"; boolean f2=str2.matches(regex1); System.out.println(f); //获取IP地址(192.168.1.100)中的每段数字 String regex3="[0-9]{3}\\.[0-9]{3}\\.[0-9]{1,3}\\.[0-9]{3}"; String str3="192.168.52.165"; boolean f3=str3.matches(regex3); System.out.println(f3); } }