我正在使用PowerGrep的正则表达式来搜索一堆文件.我正在使用java文件,我的目标是找到块中不包含单词的所有catch 块,log以便我可以添加日志记录.有很多文件,所以手动浏览它们并不可行.
应该找到什么的例子
catch (Exception e) {
//comment#
int math = 1 +2 * (3);
String email = "email@example.com";
anothermethod.call();
//no logging
}
Run Code Online (Sandbox Code Playgroud)
和
catch(AnotherException e ) {} //no logging
Run Code Online (Sandbox Code Playgroud)
不应该找到什么的例子
catch(AnotherException e ) {
//some code
log.error("Error message");
//some more code
}
Run Code Online (Sandbox Code Playgroud)
和
catch(BadE_xception e) { log.error(e); }
Run Code Online (Sandbox Code Playgroud)
我对正则表达式不是很有经验,但这是我到目前为止所拥有的:
catch块开始: catch\s*\(\s*\w*\s+\w*\s*\)\s*\{.*?
但后来我不确定从哪里开始指定不包含log.如果你有关于如何在没有正则表达式的情况下做到这一点的想法,那对我来说也是完美的.谢谢
我在每一行都有两个字符串的长列表,数字字符串和字母数字字符串(每个原始字符串的长度不同),我想更改(切换)位置:
010110,file_1.txt
0120100,file_11.txt
Run Code Online (Sandbox Code Playgroud)
要有这个:
file_1.txt,010110
file_11.txt,0120100
Run Code Online (Sandbox Code Playgroud)
第二个字符串还包括点和下划线,如上例所示。我尝试了之前用于类似任务的正则表达式,但它不起作用,我在 Notepad++ 和 Powergrep 中尝试过。
([^_]*),(.*)
Run Code Online (Sandbox Code Playgroud)
用。。。来代替:
\2_\1
Run Code Online (Sandbox Code Playgroud)
试过那个正则表达式(有变化)但没有结果。