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

Asked

Viewed 69 times

2

I’m trying to involve everyone console.log(); of my code with the condicional if(showLog) { }. I was learning regex and found I could select all the expressions console.log() including those separated in several lines by eclipse formatting, however, I could not make the selected section finish in ;, so that the beginning passage of an expression console.log() until the end of the code, which ended in ;, was selected. Someone would tell me how to make the selected expression only go to the first ; what to find?

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

Unfortunately it is not possible that I post all the code here, but I will put down examples in which I have been testing:

console.log();
console.log("ok");  
console.  
log("ok");  
console  
.log("hey" +  
"guys");  

1 answer

2


You can use [^;]+, searching for "everything" but ;, once or more.

Your regex could be like this (example):

console[\s\n\.]+log\([^;]*\);
  • Funny, in http://regexr.com/ it works, however in eclipse it does not find any corresponding excerpt

  • @Gabrielc. I wonder if you have tabs ? try to join \t thus: console[\s\t\n\.]+log\([^;]*\);

  • 1

    Thank you so much! Now it’s working perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.