Is there an easy way to strip out all instances of:
console.log("items");
Where items is a string that's always different (different length, different text)?
Is there an easy way to strip out all instances of:
console.log("items");
Where items is a string that's always different (different length, different text)?
Here's the regex for that:
console\.log\("(\\"|[^"])*"\);
See it here in action: http://regexr.com?2vmmk
As pointed out by @Benoit, the following solution is superior to the one above:
console\.log\("([^\\"]|\\.)*"\);
See it here in action: http://gskinner.com/RegExr/?2vmmt
You could probably catch many more scenarios with this:
console\.log\(.*\);
if you're not in multiline mode, and you're sure your statements are on their own lines (meaning no other statement will be on that same line).
If they're not on their own lines, you might try this:
console\.log\([^;]\);
but this'll not match this piece:
console.log( (function(){ return 3*4; })() );
or even this:
console.log(";");
since they have a ;
in the middle.
In conclusion: it all depends on your needs, which haven't been clearly specified.
Use:
console\.log\("([^\\"]|\\.)*"\);
This will eat each backslash with the next character, and eat no quote.
In action: http://regexr.com?2vmmt