Package Test;import java.util.regex.matcher;import java.util.regex.pattern;/** mailbox: @ Front contains 5-14 digits, letter underline, @ behind is QQ, 126,163,yahoo,gmail,sina, then COM or CN. * Phone Number: 11 digits, the first two digits are 13,15,16,17,18,19* identity card 18 bits: 5 Start, 7th, 8 digits 19 or 20, 11th digit 0 or 1, 13th digit 0 or 1 or 2 or 3, 18th bit may be x* domain name: www, then a ".", followed by a number or letter or underscore (unlimited length), followed by ".", COM or cn or com.cn. */public class Test1 {public static void main (string[] args) {Pattern P1 = Pattern.compile ("^\\w{5,14}@ (qq|126|163|yahoo| Gmail|sina) \ \. (COM|CN) $ "); Matcher m1 = P1.matcher ("[email protected]"); System.out.println (M1.matches ()); Pattern P2 = pattern.compile ("^1 (3|4|5|6|7|8) \\d{9}$"); Matcher m2 = p2.matcher ("15623479501"); System.out.println (M2.matches ()); Pattern p3 = Pattern.compile ("^5\\d{5} (19|20) \\d{2} (0|1) \\d (0|1|2|3) \\d{4} (x|[ 0-9]) $ "); Matcher m3 = p3.matcher ("54614719281231468X"); System.out.println (M3.matches ()); Pattern P4 = Pattern.compile ("^ (www|www) \\.\\w{1,}\\." ( com|cn|com.cn) $ "); Matcher M4 = P4.matcher ("www.dgjfgkhkg345476.com.cn"); System.out.println (M4.matches ());}}
1, "." "+" "?" "*" matches, preceded by "\ \"
2, ID card within the date of the match there is a small problem, such as 19900228, when the month is 02 o'clock, the date can not exceed 28, the other months also have similar restrictions, which in the regular expression there is no quick solution (in addition to the monthly write out)?
Regular expression attempts