Javascript string. Replace Function

Source: Internet
Author: User

The string built-in function Replace (Regexp, newstring) of JavaScript provides the string replacement function. From the function prototype, we can see that regular exp is supported. This function is very practical, but there are also a few obfuscation points. The following uses actual examples to illustrate:

For example

VaR src = "<a href = & quot; http://xx.com/a/20100601/000224.htm&quot; target = & quot; _ blank & quot;> XXX </a>"

The Escape Character of the HTML double quotation marks to be replaced& Quot;For the actual"Normally, we will directly callSRC. Replace (/& quot;/g ,'"');To achieve the goal, but Javascript is easy to confuse. In this way, the SRC value is not actually changed. The actual test shows that the returned value is the result we need, SRC itself does not change, so we need to complete our functions as follows:

 

Src = SRC. Replace (/& quot;/g ,'"');

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.