Package Date0804.demo1;import Java.util.regex.pattern;public class Regularexpres {public static void main (string[] args {//The brackets represent only one character, * represents any bit, and the question mark represents a bit//match with the first letter A, the end letter B of any string Boolean B1 = Pattern.matches ("A*d", "Aaaaad");//matches the first letter A, Any string that has the middle of the letter B at the end of any character (including the null character) is a Boolean b2 = Pattern.matches ("A?d", "ad"), and/or any string that matches the first letter A, the letter B at the end, and a or B or C in the middle, boolean b3 = Pattern.matches ("A[abc]d", "abd");//Match First letter A, end letter B, middle of any string excluding A or B or c boolean b4 = pattern.matches ("A[^abc]d", "Abd") ;//Match A-Z or a-Z any character boolean b5 = Pattern.matches ("[A-za-z]", "a");//a-d,m-pboolean B6 = pattern.matches ("[A-dm-p]", "L"); /d,e,fboolean B7 = Pattern.matches ("[A-z&&[def]]", "D");//a-d,m-pboolean B8 = Pattern.matches ("[A-dm-p]", "L") ;//digitboolean B9 = Pattern.matches ("[0-9]", "?");}}
Example of pattern matching for Java regular expressions