1. Get Features:
Pattern and Matcher classes are used together
2. Use case:
1 Packagecn.itcast_05;2 3 ImportJava.util.regex.Matcher;4 ImportJava.util.regex.Pattern;5 6 /*7 * Get features8 * Use of pattern and Matcher classes9 * Ten * Basic Use order of the pattern and the matching device One */ A Public classRegexdemo { - Public Static voidMain (string[] args) { - //Typical invocation order of patterns and matches the //compiling regular expressions into schema objects -Pattern p = pattern.compile ("A*b"); - //The matching object is obtained by the pattern object, which is what is needed to match the string -Matcher m = P.matcher ("Aaaaab"); + //the ability to invoke a match object - Booleanb =m.matches (); + System.out.println (b); A at //This is a judgment function, but if you make a judgment, it's a bit of a hassle, we do it directly using the string method . -String s = "Aaaaab"; -String regex = "A*b"; - BooleanBB =s.matches (regex); - System.out.println (BB); - } in}
The results are as follows:
Java Fundamentals Hardening 78: The acquisition of regular expressions (use of Pattern and Matcher classes)