Java-regular, java-
Regular Expressions are common. But it is also very error-prone. Therefore, the methods for writing Java regular expressions are sorted out. Pattern ). Split (split _ into an array ). Compile (Compilation), matcher (matcher). + indicates that any unempty, \. indicates that the translation starts with ". ^" and ends with "$? It indicates the lazy mode. If the first matching condition is met, it will stop *: 0 to infinity +: 1 to infinity \ d Number: [0-9] \ D non-digit: [^ 0-9] \ w numbers and letters [a-zA-Z0-9] \ W non-numbers and letters [^ a-zA-Z0-9]
- In some languages, "\" means "inserting a backslash in a regular expression. "But in Java," \ "means" to insert a backslash of a regular expression,
- The java regular expression should be "\ w + ". If you want to insert a backslash, you must use "\\\\".
- Java only uses a backslash "\ n \ t" for line breaks and grid jumps ".
Example: Pattern pattern = Pattern. compile ("[, |] + ");
String [] strs = pattern. split ("Java Hello World Java, Hello, World | Sun ");
For (int I = 0; I <strs. length; I ++ ){
System. out. print ("\ t" + strs [I]);
} The output is: Java Hello World Sun verified email address: String str2 = "ceponline@yahoo.com.cn ";
Pattern pattern5 = Pattern. compile (". + @. + \... +? ");
Matcher matcher5 = pattern5.matcher (str2 );
System. out. print ("\ n" + matcher5.matches (); // return a Boolean value to remove the html Tag:
Pattern pattern6 = Pattern. compile ("<. +?> ");
Matcher matcher6 = pattern6.matcher ("<a href = \" index.html \ "> homepage </a> ");
String string = matcher6.replaceAll ("");
System. out. println ("\ r" + string );
// Intercept the url
Pattern pattern8 = Pattern. compile ("Matcher matcher8 = pattern8.matcher ("dsdsds If (matcher8.find ()){
System. out. println (matcher8.group (); // returns the matched string.
} Simple: example: String str = "Regular Expression Hello World, regular expression Hello World"; str. replace ("hello", "I want to replace hello") filter the number public Double regexGetMath (String matcher ){
Pattern pattern = Pattern. compile ("[^ 0-9/.]");
Matcher match = pattern. matcher (matcher );
String getStr = match. replaceAll ("");
Double getNum = Double. parseDouble (getStr );
Return getNum;
} Filter String public String regexGetLetterLow (String matcher ){
Pattern pattern = Pattern. compile ("[^ a-zA-Z]");
Matcher match = pattern. matcher (matcher );
String getStr = match. replaceAll (""). toLowerCase ();
Return getStr;
}