Home  >  Article  >  Web Front-end  >  javascript matches regular expression code commented in js

javascript matches regular expression code commented in js

小云云
小云云Original
2018-01-08 10:18:042356browse

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!

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