package cn.zhengze; import java.util.ArrayList; import java.util.Arrays; public class zhengze { /** * @param args */ public static void main(String[] args) { //test1(); // test2(); test3(); } public static void test1() { String temp = 我我我.......我要學...學學學...編編編程程..; temp=temp.replaceAll(\.+, ); temp=temp.replaceAll((.)\1+, $1); System.out.println(temp); } private static void test2() { /* * 對ip地址排序 * */ String temp = 192.168.1.200 17.1.10.10.10 3.3.50.3 127.0.0.1; temp=temp.replaceAll((\d+),00$1 ); temp =temp.replaceAll(0*(\d{3}), $1); String[] ips =temp.split( +); Arrays.sort(ips); for(String ip:ips) { System.out.println(ip.replaceAll(0*(\d+), $1)); } /* 結果: * 3.3.50.3 17.1.10.10.10 127.0.0.1 192.168.1.200 */ } private static void test3() { /* * 校檢郵箱地址 */ String mail = [email protected]; String regex=\w+@[a-zA-Z0-9]+(\.[a-zA-Z]{2,3}){1,3}; boolean b =mail.matches(regex); System.out.println(mail+:+b); } }