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