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