How to replace regular expressions in javascript

coldplay.xixi
Release: 2023-01-04 09:35:40
Original
5780 people have browsed it

javascript正则表达式使用替换的方法:使用的是【replace()】方法,语法为【stringObject.replace(regexp,replacement)】。

How to replace regular expressions in javascript

本教程操作环境:windows7系统、javascript1.8.5版,DELL G3电脑。

javascript正则表达式使用替换的方法:

正则表达式替换使用的是replace()方法。Replace()方法是用一些字符途欢另一些字符

语法:

stringObject.replace(regexp,replacement)
Copy after login

如果 regexp 具有全局标志 g,那么 replace() 方法将替换所有匹配的子串。否则,它只替换第一个匹配子串。

replacement 可以是字符串,也可以是函数。如果它是字符串,那么没有匹配都将由字符串替换。但是 replacement 中的 $ 字符具有特定的含义。举例:

Copy after login

Instanceof

     
Copy after login

Location:

     
Copy after login

Screen:

     
Copy after login

相关免费学习推荐:javascript(视频)

The above is the detailed content of How to replace regular expressions in javascript. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!