A regular expression to match C-like (/* … */
& //...
) comments in JavaScript, PHP, Java, Kotlin, Go, C/C++, Swift, and C#.
/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm
Matches:
- // comment
- /* comment */
Non-matches:
- <!– HTML comment –>
- const a = b
A regular expression to match C-like (/* … */
& //...
) comments in JavaScript, PHP, Java, Kotlin, Go, C/C++, Swift, and C#.
/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm