Home > Web Front-end > JS Tutorial > body text

javascript matches regular expression code commented in js

小云云
Release: 2018-01-08 10:18:04
Original
2373 people have browsed it

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
Copy after login

2. Single-line comment regular expression:


/(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/g
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template