Regular expressions: used primarily for pattern recognition of strings, to determine whether a string conforms to the required format
package Everydaypratise;import Java.util.regex.matcher;import Java.util.regex.pattern;public class regextest1{public static void Main (string[] args) {//1. Determine if a string is a numeric representation The String S1 = "02143435"; Boolean B1 = S1.matches ("[0-9]+"); System.out.println (B1); S1 = "a02.143435"; B1 = S1.matches ("[0-9]+"); System.out.println (B1); 2. Use the pattern pattern P = pattern.compile ("[0-9]+"); Matcher Matcher = P.matcher ("432345"); System.out.println (Matcher.matches ()); 3. If you want to determine whether a string contains a substring of the mode to be judged P = pattern.compile ("[0-9]+"); Matcher = P.matcher ("432345-"); Determine whether the input string 432345-conforms to the pattern: [0-9]+ System.out.println (Matcher.matches ()); Determines whether the input string 432345-contains a substring that conforms to the pattern, but the starting point is not 0 System.out.println (Matcher.find ()); Matcher.reset (); System.out.println (Matcher.find ()); }}
java-Regular Expressions