Use regular expressions to replace all js functions.

Source: Internet
Author: User

Alert ("abacacf". replace ('A', '9 '));
Alert ("abacacf". replace (/a/g, '9 '));
Result 9 of the first run: bacaf, which replaces the first
The second running result 9b9c9f can be used to replace all js functions.
In fact, the second point is to use a regular expression to replace g globally to represent gobal.

Appendix: Global replacement with special symbolsCopy codeThe Code is as follows: <! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
<Script language = "javascript" type = "text/javascript">
String. prototype. replaceAll = stringReplaceAll;
Function stringReplaceAll (AFindText, ARepText ){
Var raRegExp = new RegExp (AFindText. replace (/([\ (\) \ [\] \ {\} \ ^ \ $ \ + \-\*\? \. \ "\ '\ | \/\])/G," \ $1 ")," ig ");
Return this. replace (raRegExp, ARepText );
}
Function myreplace (){
Var content = document. getElementById ("content"). value;
Var rel_con = content. replaceAll ("$ name", "wwww ");
Document. getElementById ("content2"). value = rel_con;
}
</Script>
</HEAD>
<BODY>
<Input type = "text" id = "content" name = "contxt" value = "$ name customer name"/> <input type = "button" value = "replace"
Onclick = "myreplace ()"/> <br/>
<Input type = "text" id = "content2" value = ""/>
</BODY>
</HTML>

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.