Which of the four functions is used? And which of the following?
Solution:
1. If you only want to know whether the character is correct or not, use match
2. replace an existing string with another character.
3. You want to convert a string into multiple strings in a custom manner. Cut to obtain strings other than the rule.
4. obtain the required string.
Import Java. util. *; Class regextext {public static void main (string [] ARGs) {// test_1 (); // test_2 (); test_3 () ;}// requirement: convert the following string to: I want to program public static void test_1 () {string STR = "I am... I am... I want ..... to ..... learning ..... programming .... "; STR = Str. replaceall ("\\. + "," "); system. out. println (STR); STR = Str. replaceall ("(.) \ 1 + "," $1 "); system. out. println (STR);}/* sort the IP address segments in the order of 192.68.1.254 102.49.23.013 10.10.10.10 2.2.2.2 8.109.90.30 */public static void test_2 () {string IP = "192.68.1.254 102.49.23.013 10.10.10.10 2.2.2.2 8.109.90.30"; IP = IP. replaceall ("(\ D +)", "00 $1"); system. out. println (IP); IP = IP. replaceall ("0 * (\ D {3})", "$1"); system. out. println (IP); string [] arr = IP. split (""); treeset <string> TS = new treeset <string> (); For (string S: ARR) {ts. add (s) ;}for (string S: TS) {system. out. println (S. replaceall ("0 * (\ D +)", "$1 "));}}}