سؤال

I know how to search and replace strings with Sublime Text2 but not when escape characters are used.

For the following javascript code can someone tell me how to escape the parentheses here?

if(PRODUCTION) console.log("hello world");

var log=function(message){
   if(!PRODUCTION) console.log(message);
};

The following does not work but seems close to being right:

find: if(PRODUCTION) console.log("(\w+)");

replace: log($1);

The ultimate goal is to only do console logging if in a development and not a production environment.

هل كانت مفيدة؟

المحلول

Escape special characters with backslash:

Find: if\(PRODUCTION\) console.log\((".+?")\);

Replace: log($1)

Note that \w+ won't match hello world, because \w doesn't match space. I've changed it to .+? so it will match anything until the matching doublequote.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top