For one line "//" comments
^\s*//.*$
For inline "//" comments
(?<!:)//.*
For one line
<!-- -->
comments
^\s*<!--.*$
For inline
<!-- -->
comments
<!--(?!.*\|).*?-->
for One line "/* */" comments
^\s*/\*.*?\*/\s*$
or
^\s*/\*.*\*/\s*$
for inline "/* */" comments
/\*.*?\*/
For multi-line block comments (JS/C/Java)
/\*[\s\S]*?\*/
For all single-line and block comments (JS/TS, one pass)
(//.*$)|(/\*[\s\S]*?\*/)
For TODO or FIXME comments (anywhere)
//.*\b(TODO|FIXME)\b.*
For Python one-line comments
^\s*#.*$
For Python inline comments
(?<!['\"])#.*
For HTML multi-line comments
<!--([\s\S]*?)-->
For removing empty lines (cleanup)
^\s*$
For trailing whitespace (cleanup)
[ \t]+$
Tips:
- Always test regex on a copy of your code!
- For multi-line patterns, enable the "dotall" or "s" flag if your tool supports it.
- Some patterns may need tweaking for your editor or language.