Regular Expressions 101

Community Patterns

Replace singleline comments with `//` or `/*...*/`, and also multi-line comments in json files.

2

Regular Expression
ECMAScript (JavaScript)

/
(\/\/.*| ?\/\*[^]*?\*\/)(,?)$
/
gm

Description

This has been validated against a tsconfig.json file that i'm using and nothing else. It should work fine though.

You can use this to replace comments with vscode find and replace, but using the regex in the search field, and '$2' without quotes in the replace field.

Submitted by anonymous - 3 years ago