Home > Article > Web Front-end > javascipt regular expression to match single-line and multi-line comments_javascript tips
When using node.js. If we use a .json file to store some configurations, we want to add some comments.
However, when reading, the string is read and then JSON.parse is used to convert it into a json object. Due to the existence of comments, it cannot be converted correctly or even an error is reported.
The following regular expression matches all comments in the string, including single-line and multi-line comments