Home  >  Article  >  Web Front-end  >  Regular matching of comments in js

Regular matching of comments in js

php中世界最好的语言
php中世界最好的语言Original
2018-03-29 10:55:032807browse

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
2 .Single-line comment regular expression:

/(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/g
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!

Statement:
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