Text Processingflags: g
C-Style Block Comment
Match C-style /* ... */ block comments across multiple lines.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
\/\*[\s\S]*?\*\/ (flags: g)Raw source: \/\*[\s\S]*?\*\/
How it works
\/\* matches the literal `/*`. [\s\S]*? lazily matches any characters including newlines (the [\s\S] idiom avoids needing a dotAll/s flag). \*\/ matches the closing `*/`. Lazy matching ensures adjacent comment blocks aren't merged into one giant match.
Examples
Input
/* one */ var x = 1; /* two\nlines */ y = 2;Matches
/* one *//* two\nlines */
Input
/** JSDoc here */Matches
/** JSDoc here */
Input
// not a block commentNo match
—Common use cases
- •Stripping comments from source for minification
- •Extracting JSDoc / Doxygen blocks for documentation
- •Linting commented-out code
- •Translating comment styles between languages