Java regular expression-string matching, cutting, and replacement

Source: Internet
Author: User

 

Package RegEx; public class regexs {public static void main (string ARGs []) {// Regular Expression cut // splitshow ("Monday, Tuesday, third ",","); // splitshow ("moday. tureday. third ","\\. "); // follow. cut // splitshow ("moday Tuesday third", "+"); // cut by space // splitshow ("C: \ Windows \ System ", "\\\\"); // file path cutting // splitshow ("dafakkafafgjjjfafaaa", "([A-Z]) \ 1 + "); // replaceallshow ("afa461341af13463420.afawfafa", "\ D {5, 10}", "#") for overlapping word cutting // Replace the regular expression }","#"); // replace the number with #/** to remove the repeated characters in a string. This is useful in ***/replaceallshow ("aaabbbcddd", "([A-Z]). \ 1 + "," $1 "); // remove duplicate connections, only one}/** Regular Expression cut ***/public static void splitshow (string STR, string RegEx) {string result [] = Str. split (RegEx); For (string S: result) system. out. println (s);}/** replace regular expression ***/public static void replaceallshow (string STR, string RegEx, string newstr) {STR = Str. replaceall (RegEx, newstr); system. out. println (STR );}}

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.