Describes how to use the JS Regular Expression replace and the jsreplace
Before talking about the advanced application of replace, let's sort out several important knowledge points in JS regular expressions to help you review your basic knowledge,
In many projects, we often need to use JS, in front of the front page to do some of the elements to make changes, JS replace () method is essential.
Frequent use of "abcabcabc". Replace ("A", "B") students should be more clear, the final result of
In the study of Baidu front-end College JS course encountered such a practice "remove string str, the place of continuous repetition",My own practice is to change the string to array a, create an empty array B, loop through group A, and then take an
In js, we can use replace () to replace the characters, numbers, or letters in the string, or replace () with regular expressions, below I will introduce some common methods of character replacement.
For example
The Code is as follows:
Share experiences on using the Replace method in JS, and share experiences with replace
Recently, I checked a bug because of the Replace method in JS. When a string needs to be replaced, the Replace method in JS is generally used, if the first
Test nickname: jesse $
View code: Javascript codeCopy codeThe Code is as follows: $ id ("f_msg_grow_1 "). innerHTML = msg ["not_club"] ["grow_value"]. replace (// {NICK_NAME}/, this.info ["friend"] ["nick_name"]);
The code will soon notice two
Http://www.jb51.net/article/25313.htmRegular expressions can:• Test a pattern for a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data
Use js to replace all characters except numbers and commasCopy codeThe Code is as follows:
Result:
Copy codeThe Code is as follows:345345, 345345Complete code:
Copy codeThe Code is as follows:FCKinsertdown. Add = function (strtemp, str ){If (strtemp.
Before we talk about the advanced application of replace, we first comb a few important knowledge points in JS, to help you review the basics, then explain the use of JS regular expressions in replace, and a few classic cases.
First, the creation
Some time ago I wrote a pop-up dialog box for js data verification, js email verification, js url verification, js length verification, and js digital verification. However, the unfriendly method is not very popular, so I wrote a new one, which is
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.