jquery implements the method of all string substitution _jquery

Source: Internet
Author: User

The example in this article describes jquery's method of implementing a full string replacement. Share to everyone for your reference, specific as follows:

Unlike the C # String type Replace method, the replace of jquery can only replace the first matching content.

For example:

var str = "a<br/>b<br/>c<br/>";
var newstr = str. Replace ("<br/>", "");
alert (NEWSTR); Content for:ab<br/>c<br/>

To replace all occurrences, you can use regular expressions:

var str = "a<br/>b<br/>c<br/>";
Re = new RegExp ("<br/>", "G"); Defines the regular expression
//The first parameter is the content to be replaced, and the second parameter "G" represents the replacement of all (global).
var newstr = str. Replace (Re, ""); The first argument is a regular expression.
//This example replaces all occurrences with the second argument.
alert (NEWSTR);//content: ABC

PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:

JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript

Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg

More about jquery related content to view the site topics: "jquery string Operation Tips Summary", "jquery Operation XML Skills Summary", "JQuery Extended Skills Summary", "jquery selector usage Summary" and "jquery common Plug-ins and Usage summary"

I hope this article will help you with the jquery program design.

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.