java - Regex to replace logging -


i add stacktrace error logging, anywhere have

try {     dosomething(); } catch (exception ex) {     something();     logger.severe("oops");     something(); } 

i have this:

try {     dosomething(); } catch (exception ex) {     something();     logger.log(level.severe,"oops",ex);     something(); } 

the exception variable can ex, e etc.

i created regex, quite slow , not work expect.

regex:

((?s:.)*catch\s*\(\s*exception\s*(.+)\s*\)\s*\{(?s:.)*logger\.)severe\(((?s:.)*?)\);((?s:.)*) 

replace:

$1log(level.severe,$3,$2); $4 

it replaces

try {   dosomething(); } catch (exception ex) {     something();     logger.severe("oops");     something(); }  {    logger.severe("oops2"); } 

to

try {   dosomething(); } catch (exception ex) {     something();     logger.severe("oops");     something(); }  {    logger.log(level.severe,"oops2",ex);  } 

use lazy matchers instead of greedy ones. refer java.util.regex.pattern documentation more details.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -