Home >Web Front-end >JS Tutorial >javascript matches regular expression code commented in js
This article mainly introduces how regular expressions match comments in JavaScript code. The code is given directly below. Friends who need it can refer to it. I hope it can help everyone.
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 comment regular expression:
/(?:^|\n|\r)\s*\/\*[\s\S]*?\*\/\s*(?:\r|\n|$)/g
2. Single-line comment regular expression:
/(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/g
Related recommendations:
Detailed explanation of using regular expression query examples in MySql
How to use regular expressions in Javascript
JS uses regular expressions to find the length of the longest continuous substring
The above is the detailed content of javascript matches regular expression code commented in js. For more information, please follow other related articles on the PHP Chinese website!