Regular Expression ---- group overlapping words

Source: Internet
Author: User

Requirement

Convert the following string to: I want to learn programming:

I am... I am... I want .. to... to... learning .. learning... editing and editing .... programming .. cheng .... cheng .. cheng.

1. Remove all. S. Replace ("\.", ""); or S. replaceall ("\. + ","");

Import Java. lang. *; import Java. util. *; Class regtext {public static void main (string [] ARGs) {text (); ipsort ();} public static void text () {string S = "I am... I am... I want .. to... to... learning .. learning... editing and editing .... programming .. cheng .... cheng .. cheng. "; // s = S. replaceall ("\\. + "," "); // remove the character. Replace S = s with an empty string. replace (". "," "); system. out. println ("[" + S + "]");}/* sort IP addresses in the order of CIDR blocks 192.168.1.254 102.49.23.103 10.10.10.5 2.2.2.2 127.0.0.1 in the natural order of strings, as long as each segment is set to three digits, each segment can be set to one, and each segment requires a maximum of zero digits. Therefore, each segment must have at least three digits and two digits, retain only three IP addresses for each segment. All IP addresses are 3-bit and 3-bit for each segment. Remove the sorted IP address output 0. */public static void ipsort () {string IPS = "192.168.1.254 102.49.23.103 10.10.5 2.2.2.2 127.0.0.1"; // fill in three 0ips = IPs for all IP segments. replaceall ("(\ D +)", "00 $1"); system. out. println (IPS); // retained the last three IPS = IPs. replaceall ("0 * (\ D {3})", "$1"); system. out. println (IPS); // cut string [] IP = IPs by space. split ("+"); For (string S: IP) {system. out. println (s);} system. out. println ("================");/* // sort the IP addresses in a natural order. arrays. sort () method arrays. sort (IP); For (string S: IP) {// remove the value 0 before the field S = S. replaceall ("0 * (\ D +)", "$1"); // remove the preceding 0 and retain the following 0system. out. println (s);} */treeset <string> TS = new treeset <string> (); For (string S: IP) {// Adding IP addresses to the set will automatically sort ts. add (s) ;}for (string S: TS) {// remove the 0 in front of the field S = S. replaceall ("0 * (\ D +)", "$1"); system. out. println (s );}}}


This article comes from "either desperate or rolling back !" Blog, please be sure to keep this source http://jiangzuun2014.blog.51cto.com/8732469/1440431

Regular Expression ---- group overlapping words

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.