1 Packageregex;2 3 Public classTESTREG01 {4 Public Static voidMain (string[] args) {5 //"." Represents any character6System.out.println ("a". Matches (".")));7System.out.println ("as". Matches (". S")));8 //\\d Indicates whether the number9System.out.println ("123". Matches ("\\d\\d\\d")));Ten //\\d Indicates whether it is not a number and uppercase is the opposite of lowercase. OneSystem.out.println ("Rtz2ez". Matches ("\\D\\D\\D\\d\\D\\D"))); A //\\s indicates that it is a blank character -System.out.println ("1 2 1". Matches ("\\d\\s\\s\\d\\s\\s\\d"))); - //tab also counts as a blank character theSystem.out.println ("1 2 1". Matches ("\\d\\s\\s\\d\\s\\d"))); - //\\w represents characters commonly used: a-z,a-z,_,0-9 -System.out.println ("AA B1". Matches ("\\w\\w\\s\\w\\d\\s\\d\\d"))); - //[ABCD] Indicates whether the character to match is a character in ABCD +System.out.println ("a". Matches ("[ABCD]"))); - //[a-za-d] Indicates whether the character is between A-z,a-d +System.out.print ("B". Matches ("[a-za-d]") + ","); ASystem.out.println ("B". Matches ("[a-z[a-d]]")); at //[a-za-d] Indicates whether the character is not between a-z,a-d -System.out.println ("X". Matches ("[^a-za-d]")); - //[A-z&&[def]] is represented in the middle of a-Z and is one of the Def -System.out.println ("F". Matches ("[A-z&&[def]]")); - //[A-z&&[def]] is represented in the middle of a-Z and is one of the Def -System.out.println ("a". Matches ("[a-z| | [Def]] ")); inSystem.out.println ("B". Matches ("[A-Z&&[^BC]]")); - to //[A-d[m-p]] A through D, or M through P: [A-dm-p] (union) and set + //[A-z&&[def]] D, E, or F (intersection) intersection - //[A-Z&&[^BC]] A through Z, except for B and C: [Ad-z] (subtraction) the //[A-z&&[^m-p]] A through Z, and not m through P: [A-lq-z] (subtraction) * } $}
Package regex;
public class TestReg01 {public static void main (string[] args) {//"." Represents any character System.out.println ("a". Matches (".")); System.out.println ("as". Matches (". S"));//\\d Indicates whether it is a digital System.out.println ("123"). Matches ("\\d\\d\\d");/\ \ D Indicates whether it is not a number and uppercase is the opposite of lowercase. System.out.println ("Rtz2ez". Matches ("\\D\\D\\D\\d\\D\\D"));//\\s represents a blank character System.out.println ("1 2 1"). Matches ("\\d\\s\\s\\d\\s\\s\\d"));//tab also counts blank characters System.out.println ("121". Matches ("\\d\\s\\s\\d\\s\\d"));/\ \ W represents the characters commonly used character: A-z,a-z,_,0-9system.out.println ("AA B1". Matches ("\\w\\w\\s\\w\\d\\s\\d\\d"));//[ABCD] Indicates whether the character to match is a character in ABCD System.out.println ("a". Matches ("[ABCD]"));//[a-za-d] Indicates whether the character is between A-z,a-d System.out.print ("B". Matches ("[a-za-d]") + ","); System.out.println ("B". Matches ("[a-z[a-d]]"));//[a-za-d] Indicates whether the character a-z,a-d is not System.out.println ("X". Matches ("[^ A-ZA-D]);//[A-z&&[def]] represents the middle of a-Z and is a System.out.println in Def ("F". Matches ("[A-z&&[def]]");//[ A-z&&[def]] is represented in the middle of a-Z and is a System.out.println ("a") in def. Matches ("[a-z| | [Def]] "); SyStem.out.println ("B". Matches ("[A-Z&&[^BC]]");//[a-d[m-p]]a through D, or M through P: [A-dm-p] (union)//[ A-z&&[def]]d, E, or F (intersection) intersection//[a-z&&[^bc]]a through Z, except for B and C: [Ad-z] (subtraction) [A-z&&[^m-p]]a through Z, and not m through P: [A-lq-z] (subtraction)}}
1. Basic character Matching