Home >Web Front-end >JS Tutorial >Regular matching of comments in js
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 commentsRegular expression:
/(?:^|\n|\r)\s*\/\*[\s\S]*?\*\/\s*(?:\r|\n|$)/g2 .Single-line comment regular expression:
/(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gI 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!