Java Regular Expression (3)

Source: Internet
Author: User

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 "));}}}

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.