Application of Java.util.regex pattern
1 Public Static voidMain (string[] args) {2 //simple regular match. Matches a regular expression from a given string3 //match to return true matches not to return false4String regex_0 = "(\\;|\\?| \ \ ' |\ "|%)";5String s= "Sx?fdfs ' SD";6Pattern pattern =Pattern.compile (regex_0);7Matcher Matcher =Pattern.matcher (s);8 BooleanAs=matcher.find ();//returns true to match to?9 BooleanDd=matcher.find ();//returns true Match to 'Ten BooleanSs=matcher.find ();//return False no match to special symbol One A -String Regex_1=pattern.pattern ();//returns the regular expression for the current match (\;|\?| \ ' | ' |%) -String string=pattern.tostring ();//Back (\;|\?| \ ' | ' |%) the -String regex_s= "\\d+"; - BooleanFalg=pattern.matches (regex_s, "897");//returns True - + -String regex_2= "(\ \,)"; +String on= "Sxf,sxd,dong,leng"; APattern pattern2=Pattern.compile (regex_2); atString[] Ad=pattern2.split (ON);//[Sxf, Sxd, Dong, Leng] - -String regex_3= "([0-9]+) | (\\,)"; -String on2= "SXF8SXS94SXY0DF,HSL879DZQ,XJT 45"; -Pattern pattern3=Pattern.compile (regex_3); -String[] Y=pattern3.split (on2);//[Sxf, SxS, Sxy, DF, HSL, Dzq, XJT,] inString[] X=pattern3.split (on2,3);//[Sxf, SxS, SXY0DF,HSL879DZQ,XJT 45] (when 3>0 matches 3-1 times, the array length is not greater than 3, the last of the array is the remaining string except the match) -String[] Z=pattern3.split (on2,9);//[Sxf, SxS, Sxy, DF, HSL, Dzq, XJT,] toString[] H=pattern3.split (on2,-1);//[Sxf, SxS, Sxy, DF, HSL, Dzq, XJT,] (when the second argument is <0, the number of matches is unlimited and the array length is any length) +String[] M=pattern3.split (on2,0);//[Sxf, SxS, Sxy, DF, HSL, Dzq, XJT,] -}
View Code
Application of regular Expressions in Java