Application of regular Expressions in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.