Java---Regular expressions

Source: Internet
Author: User

 Packagesad;ImportJava.util.Scanner;//The normal form is a string typeImportJavax.management.loading.PrivateClassLoader; Public classers { Public Static voidMain (string[] args) {System.out.println ("Please enter the string you want to manipulate:"); Scanner SC=NewScanner (system.in); String str1=Sc.next ();    Factory.switches (STR1); }    }classfactory{Static intchance; Static voidswitches (String str1) {Scanner sc=NewScanner (system.in); System.out.println ("Please enter the action you want to take:"); System.out.print ("\ n"); System.out.println ("1. The normal method is to make sure that the strings are all made up of numbers."); System.out.println ("2. Whether the exact set of strings is all made up of numbers"); System.out.println ("3. Delete all the numbers in the string"); System.out.println ("4: Verify that the email format is correct"); Chance=Sc.nextint (); Switch(Chance) { Case1:        NewNormalboolean (STR1);  Break;  Case2:        NewZhengzeboolean (STR1);  Break;  Case3:        NewExchangenum (STR1);  Break;  Case4:        NewTestmail (STR1);  Break; default:         Break; }    }}classnormalboolean{Normalboolean (String str)//General Methods    {           Char[] arr =Str.tochararray ();  for(inti=0;i<arr.length;i++)        {            if(arr[i]< ' 0 ' | | Arr[i]> ' 9 ') {System.out.println ("Not all by numbers."); }} System.out.println ("It's all made up of numbers."); }    }classZhengzeboolean//Regular Expressions{       PublicZhengzeboolean (String str1) {if(Str1.matches ("\\d+") {System.out.println ("Regular validation is composed of numbers"); }    Else{System.out.println ("Regular validation is not composed of numbers"); }}}classExchangenum//Delete numbers in a string{     Publicexchangenum (String str) {//TODO auto-generated Constructor stubExchange (str); }    Private voidExchange (String str) {string regex= "[0-9]+"; //String regex = "\\d++";System.out.println (Str.replaceall (Regex, "*"));//you can swap numbers for other characters    }}classTestmail//Verify that the email format is correct *****@****.****{     Publictestmail (String str) {Mail (str); }    Private voidMail (String Str) {string regex= "\\[email protected]\\w+\\.\\w+"; String regex1= "[1]";    System.out.println (Str.matches (REGEX1)); }}

Java---Regular expressions

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.