Import java. util. arraylist;
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;
Public class test {
Public static void main (string [] ARGs ){
Getstrings (); // use a regular expression to obtain the specified content in the specified string.
System. Out. println ("********************");
Replace (); // replace string content with a regular expression
System. Out. println ("********************");
Strsplit (); // use a regular expression to cut a string
System. Out. println ("********************");
Strmatch (); // String Matching
}
Private Static void strmatch (){
String phone = "13539770000 ";
// Check whether the phone number is a qualified mobile phone number (Standard: 1, the second digit is 3, 5, 8, and the last nine digits are any numbers)
System. Out. println (Phone + ":" + phone. Matches ("1 [358] [0-9] {9,9}"); // true
String STR = "abcd12345efghijklmn ";
// Check if STR contains 12345
System. Out. println (STR + ":" + Str. Matches ("\\ W + 12345 \ W +"); // true
System. Out. println (STR + ":" + Str. Matches ("\\ W + 123456 \ W +"); // false
}
Private Static void strsplit (){
String STR = "asfasf. sdfsaf. sdfsdfas. asdfasfdasfd. wrqwrwqer. asfsafasf. safgfdgdsg ";
String [] STRs = Str. Split ("\\.");
For (string S: STRs ){
System. Out. println (s );
}
}
Private Static void getstrings (){
String STR = "success ";
Pattern P = pattern. Compile ("QQ (.*?) QQ ");
Matcher M = P. matcher (STR );
Arraylist <string> STRs = new arraylist <string> ();
While (M. Find ()){
STRs. Add (M. Group (1 ));
}
For (string S: STRs ){
System. Out. println (s );
}
}
Private Static void Replace (){
String STR = "asfas5fsaf5s4fs6af. sdaf. ASF. wqre. QWR. fdsf. ASF ";
// Replace "." In the string with "_". Because "." is a special character, it must be expressed by "\." and "\" is a special character. Therefore, it must be expressed.
STR = Str. replaceall ("\\.","_");
System. Out. println (STR );
}
}