如何在 Eclipse 中使用正则表达式将大写字母替换为小写字母?
我想检查所有源代码文件,并将每次出现的 k_Xyyy
替换为 k_xyyy
(将 k_
之后的第一个字母从大写转小写)。
我正在使用 Eclipse 对话框来搜索和替换多个文件。现在我有正则表达式 \bk_([AZ])
。
如何指定正则表达式的替换字符串?
I'd like to go through all of my source code files and replace every occurence of k_Xyyy
with k_xyyy
(switch the first letter after k_
from uppercase to lowercase).
I'm using the eclipse dialog to search and replace multiple files. Right now I have the regex \bk_([A-Z])
.
How do I specify the replacement string of the regex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚利用 VIM 的强大功能解决了相同的任务(必须将 .net 接口转换为 java 接口):)
这里我们正在搜索(可选缩进,后跟返回类型,后跟空格),后跟(大写字母)。大括号是捕获组。然后我们执行替换第一个捕获组 \1 小写 \L 第二个捕获组 \2。
这当然需要您在 Vim 中打开文件,但无论如何,这比在 Eclipse 中手动执行相同的操作要快得多。
I just resolved the same task (had to turn .net interface into java interface) utilizing the power of VIM :)
Here we are searching for (optional indentation followed by return type followed by whitespace) followed by (Uppercase letter). Braces are capturing groups. Then we are performing a replacement first capturing group \1 lowercase \L second capturing group \2.
This of course requires you to open file in Vim, but anyway this is much faster then doing the same thing by hand in Eclipse.
那是不可能的。要么使用 Eclipse 的重构功能,要么一次替换它们:
That is not possible. Either use Eclipse's re-factoring functionality, or replace them one at a time:
我需要对大量源代码执行此操作,其中字符串文字需要转换为小写。我找到了一种使用 Notepad++ 和 Python 脚本插件的方法,如使用 在这里。
I needed to do this for a huge chunk of source code where string literals needed to be converted to lowercase. I found a way using Notepad++ and the Python Script plugin, as used here.
(对于我来说,因为我刚刚开始编程,所以思考这个更有趣)
获取
$pattern_to_change
并使用ord()
将其从 ASCII 转换为十进制。获取生成的十进制数并添加 32。然后将$desired_pattern
转换回来使用chr()
转换为ascii。或者只需下载
SublimeText
并使用其查找和替换功能来查找所有出现的内容并用不同的文本替换它们(Sublime 也有正则表达式)。我确信您可以手动转换 10 亿美元,因为这篇文章已经有 5 年历史了,但您可以使用 Sublime 在 5 分钟内完成此操作。
非常有用的文本编辑器。
(for me, since I just started programming, this was more fun to think about)
Take
$pattern_to_change
and convert it from ascii to decimal usingord()
.Take the resulting dec number and add 32. Then convert$desired_pattern
back to ascii usingchr()
.Or just download
SublimeText
and use its Find and Replace feature to Find All occurrences and replace them with difference text (Sublime has regex as well).I'm sure you could have converted one billion by hand since this post is like 5 years old, but you could have complete this in 5 minutes with Sublime.
Really useful text editor.