Three JS replace the specified character or string function

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax compile different example expression function how to java

Three JS replace the specified character or string function mainly to give a different example to explain how to replace the string ah, text replacement (first occurrence of characters) text replacement (all) text replacement (substitution character) Three kinds of situation oh.

Text substitution (substitution character)

Pattern Pattern.compile ("regular expression");
Matcher Matcher = Pattern.matcher ("Regular expression Hello world, regular expression Hello World");
StringBuffer sbr = new StringBuffer ();
while (Matcher.find ()) {
Matcher.appendreplacement (SBR, "Java");
}
Matcher.appendtail (SBR);
System.out.println (Sbr.tostring ());


Text substitution (first occurrence of characters)

Pattern Pattern.compile ("regular expression");
Matcher Matcher = Pattern.matcher ("Regular expression Hello world, regular expression Hello World");
Replace the first data that matches the regular
System.out.println (Matcher.replacefirst ("Java"));

Text substitution (All)

Pattern Pattern.compile ("regular expression");
Matcher Matcher = Pattern.matcher ("Regular expression Hello world, regular expression Hello World");
Replace the first data that matches the regular
System.out.println (Matcher.replaceall ("Java"));
Related Article

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.