Regular Expression 1

Source: Internet
Author: User

1 ImportJava.util.regex.Matcher;2 ImportJava.util.regex.Pattern;3 4  Public classRegexdemo {5 6      Public Static voidMain (string[] args) {7 method_5 ();8     }9 Ten     /* One * Requirements: Define a function to check the QQ number. Requirements: Length 5~15. Can only be a number, 0 cannot start A      */ -      Public Static voidmethod_1 () { -String QQ = "101885"; theString regex = "[1-9]\\d{4,14}"; -SYSTEM.OUT.PRINTLN (QQ + ":" +qq.matches (regex)); -     } -  +     /* - * Requirements: Mobile phone number verification +      */ A      Public Static voidmethod_2 () { atString Tel = "18190029004"; -String regex = "1[358]\\d{9}"; -SYSTEM.OUT.PRINTLN (tel + ":" +tel.matches (regex)); -     } -  -     /* in * Demand: Overlapping word cutting -      */ to      Public Static voidmethod_3 () { +String str = "Akjdhkahjjauuuuqjhadwww;k"; -String regex = "(.) \\1+ "; thestring[] arr =str.split (regex); *          for(String s:arr) { $ System.out.println (s);Panax Notoginseng         } -     } the  +     /* A * Requirements: Replacement 1. Mobile phone number replacement 2. Overlapping word substitution the      */ +      Public Static voidMethod_4 () { -String Tel = "13840056789"; $String regex = "(\\d{3}) (\\d{4}) (\\d{4})"; $System.out.println (Tel.replaceall (Regex, "$1****$3")); -  -String str = "Akjdhkahjjauuuuqjhadwww;k"; theString reg = "(.) \\1+ "; -System.out.println (Str.replaceall (Reg, "*"));Wuyi     } the  -     /* Wu * Need: Get three-letter words -      */ About      Public Static voidmethod_5 () { $String str = "AJKDH iqw iqiw qii,wip aido q QW"; -String regex = "\\b[a-z]{3}\\b"; -Pattern p =pattern.compile (regex); -Matcher m =P.matcher (str); A          while(M.find ()) { + System.out.println (M.group ()); theSystem.out.println (M.start () + "" +m.end ()); -         } $     } the}

Regular Expression 1

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.