在许多java文件中将string1替换为string2,仅在注释中 [英] replace string1 with string2 in many java files, only in comments

查看:330
本文介绍了在许多java文件中将string1替换为string2,仅在注释中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约3000个替换实例在数百个文件中完成。用 string2 替换 string1 的所有出现很容易。 IntelliJ允许我替换注释和字符串中的所有出现。

I have around 3000 instance of replacement done in hundreds of files. Replacing all occurance of string1 with string2 was easy. IntelliJ allows me to replace all occurences in "comments and strings".

问题是注释和实际代码中出现了相同的字符串。我想在评论部分限制替换(我们使用/ ** /或//的混合)

The problem is that the same string appear in comments and real code. I would like restrict the replacement only in comment section ( we use mix of /**/ or // )

任何可以执行此操作的库/ IDE /脚本?

Any library/IDE/script that can do this?

推荐答案

use Regexp::Common 'comment';
...
s/($RE{comment}{'C++'})/(my $x = $1) =~ s#string1#string2#g; $x/ge;

这篇关于在许多java文件中将string1替换为string2,仅在注释中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆