正则表达式
package fix; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Testzz { /** * @param args */ public static void main(String[] args) { /* //String reg="\\d{16}"; //登录名 字母数字_ 最多10位 String reg="\\w{1,10}"; String s="fix4u"; //手机号 String reg="1[358]\\d{9}"; String s="18807480089"; // 汉字 String reg="[\\u4E00-\\u9FA5\\uF900-\\uFA2D]{2,4}"; String s="abcd"; //电话 010-88888888 0731-88562176 //String reg="\\d?\\d{3}-\\d{7}\\d?"; String reg="\\d{3}-\\d{8}|\\d{4}-\\d{7}"; String s="073-12345678"; //email String reg="\\w+@\\w{2,}\\.[a-zA-Z]{2,}"; String s="fix2cn@qq.com"; Pattern p=Pattern.compile(reg); //正则 Matcher m=p.matcher(s); boolean ok= m.matches(); System.out.println(ok); */ //字符串查找 Pattern p=Pattern.compile("美国"); //正则 Matcher m=p.matcher("111-----美国---11222-美国----美国---美国"); while(m.find()){ String ok=m.group(); //找到的东西 System.out.println(ok); } } }