C-Style Block Comment
Match C-style /* ... */ block comments across multiple lines.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\/\\*[\\s\\S]*?\\*\\/", "g");
const input = "/* one */ var x = 1; /* two\\nlines */ y = 2;";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\/\*[\s\S]*?\*\/")
input_text = "/* one */ var x = 1; /* two\nlines */ y = 2;"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\/\*[\s\S]*?\*\/`)
input := `/* one */ var x = 1; /* two\nlines */ y = 2;`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\/\*[\s\S]*?\*\/ (flags: g)Raw source: \/\*[\s\S]*?\*\/
How it works
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
Related patterns
Single-Line Comment (// or #)
Text ProcessingMatch single-line comments using either the `//` (C-family) or `#` (shell, Python, Ruby, YAML) marker.
Terraform Resource Block Header
Text ProcessingMatch the opening line of a Terraform `resource "type" "name" {` block, capturing the resource type and local name.
Whitespace-Only Line
Text ProcessingMatches lines containing only whitespace (or empty lines).
Emoji (Unicode)
Text ProcessingMatch emoji characters across the main Unicode emoji ranges — requires the Unicode flag in JavaScript.