Regular expression attempts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.