Regular Expressions 101

Community Patterns

Java single line comment matcher

-1

Regular Expression
Python

r"
^(?:(((([^"\n]|(['\\]"))*?)((?<=[^\'])")){2})*[^"\n]*)(\/\/.*?)$
"
mg

Description

This regex matches java line end comments started with "//" and ignores such ones that are within String literals. (NO SUFFICIENT TESTING WAS DONE TO GUARANTEE 100% SAFETY)

Submitted by Janis Schöck - 9 years ago