Regex to wrap console.log expression in eclipse find / replace

2

I'm trying to wrap all console.log(); of my code with condicional if(showLog) { } . I was learning regex and found that I was able to select all console.log() expressions including those separated in several lines by eclipse formatting, however, I could not make the selected excerpt end in ; , so that the start snippet of an expression console.log() to the end of the code, which ended in ; , was selected. Could someone tell me how to do the selected expression just go to the first ; to find?

The expression I'm using is console[\s]*\.log\([\s\S]*(?!\))*\);

Unfortunately it's not possible for me to post all the code here, but I'll put below examples I've been testing:

console.log();
console.log("ok");  
console.  
log("ok");  
console  
.log("hey" +  
"guys");  
    
asked by anonymous 17.03.2017 / 23:58

1 answer

2

You can use [^;]+ , which looks for "everything" minus ; , once or more.

Your regex could look like this ( example ):

console[\s\n\.]+log\([^;]*\);
    
18.03.2017 / 00:01