Regular expression base application (replace ReplaceAll (REGEX,STR)) __ Regular expression

Source: Internet
Author: User

1. Base character replacement

Requirements:

Replaces a string with a number string in *


String e = "ASDLFJ328238ASLDFJLSFD32323SDFL";
String reg5 = "\\d+";
String newstr = E.replaceall (Reg5, "*");
System.out.println (NEWSTR);

Print Result: ASDLFJ**ASLDFJLSFD**SDFL


2. Replacement of overlapping words

Requirements:

To replace a duplicate string in a string with a *


String f = "ASDLFJCCCASDFZZASFD";
String Reg6 = "(.) \\1+ ";
String newStr2 = F.replaceall (Reg6, "*");
System.out.println (NEWSTR2);


Print Result: ASDLFJ*ASDF*ASFD


3. Special substitutions, based on the substitution of the above overlapping words

Requirements:

A single character that replaces repeated strings in a string with the same character value


String g = "ASDLFJCCCASDFZZASFD";
String Reg7 = "(.) \\1+ ";
String NEWSTR3 = G.replaceall (Reg7, "$"); The values that are filtered by the first group in the regular expression are shown here
System.out.println (NEWSTR3);


Print Results: ASDLFJCASDFZASFD


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.