How to implement global match and replace in javascript
How to implement global match and replace in javascript
This article mainly introduces the summary of the method for implementing global matching and replacement in javascript, which is very
The JavaScript mentioned here refers to the host environment in the browser environment. The first is the ECMAScript global object, and the second is the globally objects/functions under the Host Environment (host). One, core JavaScript built-in
Document directory
JavaScript indexOf () method
JavaScript substring () method
JavaScript split () method
JavaScript replace () method
JavaScript indexOf () method definition and usage
The indexOf () method returns the position of the first
String. Replace ()
Syntax:
String. Replace (Regexp, replacement)
Regexp: the regular expression of the replacement operation. If a string is input, it is processed as a normal character and only one replacement operation is performed. If it is
Document directory
Enter:
Because the replaceall () method is not provided in Javascript, it is not very comfortable to use. Next I will show you how to use the replace method to obtain columns with other effects, such as the replaceall effect.
The built-in objects are defined as:Provided by the JavaScript implementation and not created by yourself, these objects already existed before the ECMAScript program was executed.This means that developers do not have to instantiate the built-in
Definition and UsageThe replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.Stringobject.replace (regexp/substr,replacement)
Parameters
From: http://www.w3school.com.cn/jsref/jsref_replace.aspDefinition and usageThe replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular
In JavaScript, the replace function is used as a string replacement function, which is a powerful string operation function and is recommended for common string operations. This article will give you a deeper understanding of it. The replace
Definitions and usage
The replace () method replaces some characters in a string with some other characters, or replaces a substring that matches a regular expression.
Stringobject.replace (regexp/substr,replacement)
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.