Home > Web Front-end > JS Tutorial > body text

Regular matching of comments in js

php中世界最好的语言
Release: 2018-03-29 10:55:03
Original
2749 people have browsed it

This time I will bring you the regular rules for matching annotations in js, and what are the precautions for matching the regular rules for annotations in js. The following is a practical case, let's take a look.

Sometimes we need to remove js comments to reduce redundancy in the code. Sometimes too many comments lead to a large page size.

The comment icon is as follows:

1. Match multi-line comments

Regular expression:

/(?:^|\n|\r)\s*\/\*[\s\S]*?\*\/\s*(?:\r|\n|$)/g
Copy after login
2 .Single-line comment regular expression:

/(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/g
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the use of the \D metacharacter (equivalent to "[^0-9]") in regular expressions

Regular metacharacters and ordinary characters

The above is the detailed content of Regular matching of comments in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
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!