100% Client-Side β’ 0 B Data Leaves Browser
formatting
C-Style Code Comment Regex
Matches single-line (//) and multi-line (/* ... */) code comments across JavaScript, C, Java, Go, and PHP.
Regular Expression Pattern:
/\/\*[\s\S]*?\*\/|\/\/.*/g
Valid Match Example:
/* Multi-line comment block */ // single line comment
Invalid / Non-Match Example:
const x = 10 / 2;
Regex Syntax Breakdown & Explanation
- β’\/\*[\s\S]*?\*\/ : Non-greedy match of multi-line comment blocks
- β’| : Logical OR operator
- β’\/\/.* : Single line comment from double slash to end of line
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /\/\*[\s\S]*?\*\/|\/\/.*/g;
const isValid = regex.test("/* Multi-line comment block */ // single line comment");
console.log(isValid); // truePython (re)
import re pattern = r"\/\*[\s\S]*?\*\/|\/\/.*" match = re.match(pattern, "/* Multi-line comment block */ // single line comment") print(bool(match)) # True
Go (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\/\*[\s\S]*?\*\/|\/\/.*`)
fmt.Println(re.MatchString("/* Multi-line comment block */ // single line comment"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /\/\*[\s\S]*?\*\/|\/\/.*/g. Matches single-line (//) and multi-line (/* ... */) code comments across JavaScript, C, Java, Go, and PHP.