Fabian Maass
asked on
How to match a String with regular expressions, but don't match commented lines?
Hi,
i want to find javascript files, that contain the line "console.log" but only if this is uncommented. Like so:
this will match:
if (t.logEnabled() && typeof console != "undefined" && console.log) {
console.log(obj);
}
this won't match:
// if (typeof console != "undefined" && console.log) {
// console.log(message);
// console.log("something else");
i thought this would do it, but apparently its not really correct:
[^\/\/].*console\.log.*
I am aware that <!-- -> are also valid JavaScript comments, but i would put this aside for the moment.
Thank you for your help
fabian
i want to find javascript files, that contain the line "console.log" but only if this is uncommented. Like so:
this will match:
if (t.logEnabled() && typeof console != "undefined" && console.log) {
console.log(obj);
}
this won't match:
// if (typeof console != "undefined" && console.log) {
// console.log(message);
// console.log("something else");
i thought this would do it, but apparently its not really correct:
[^\/\/].*console\.log.*
I am aware that <!-- -> are also valid JavaScript comments, but i would put this aside for the moment.
Thank you for your help
fabian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you, i'll take ^[^//]*console\.log, this works perfectly fine.
(also im not sure why you think your case would fail, because the "/" is not at the start of the line / no comment)
closely after asking the question here, i realized i could do it as well in two steps (search for match, discard lines that start with //)
thanks for your help