I'm not too hot when it comes to regular expressions, so I've decided to document every battle won, however big or small, in my war on regular expressions.
The problem
Parse the following snippet of Stylus and remove all the comments, while ignoring all the glob patterns in the @require
statements, to fix this issue with Stylint:
/* 'aa/' */
/*!test*/
/* someone said 'hello' */
/* "hello"*/
/***test****/
/******
'test'
****/
/****
test
****/
// let's try a single quote here "test"
/*
test
*/
/*'test'*/
/*
test
*/
/*
'test ' */
/** @require 'aa/*' */
.test
content ''/* test */
@require 'aaa/*'
@require 'bbb/*' /* test */
@require 'ccc/*'
@require 'ccc/* ab */' /* test */
@require 'ddd/*' /*test '*/
@require "ddd/*" /*test '*/
@require 'eee/*'
// test again
@require 'fff/*'
@require 'ggg/*'
@require 'hhh/*'
@require 'iii/*'
@require 'jjj/*' /* test */
@require 'kk/**/*'
The other-worldly solution from Ross Patton
/(\r\n|\n|\r)|(^(\/\*)|([\s'"](\/\*)))(?!\/)(.|[\r\n]|\n)+?\*\/\n?/gm