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