Regular Expressions 101

Community Patterns

Remove double-slash comments

0

Regular Expression
Python

r"
("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|(?:[^/\n"']|/[^/*\n"'])+|\n)|(/\* (?:[^*]|\*[^/])*\*/)|(?://(.*)$)$
"
gm

Description

This regex removes double-slash comments while avoiding anything between 'quotes' or "double quotes".

Submitted by jlacroix - 9 years ago