Eclipse,正则表达式搜索和替换 [英] Eclipse, regular expression search and replace

查看:295
本文介绍了Eclipse,正则表达式搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中,执行正则表达式搜索和替换时,可以使用匹配的搜索字符串作为替换字符串的一部分吗?



基本上,我想替换所有出现的

  variableName.someMethod()

with:

 ((TypeName)variableName.someMethod())

其中 variableName 可以是任何变量名。



sed 中,我可以使用以下内容:

  s / [a-zA-Z] + \.someMethod\(\)/((TypeName)&)/ g 

即,& 表示匹配的搜索字符串。在Eclipse中有类似的东西吗?



谢谢!

解决方案

是,()捕获一个组。您可以再次使用$ i,其中我是第i个捕获组。



so:

 搜索:(\w + \.someMethod\(\))
替换:((TypeName)$ 1)
/ pre>

提示:文本框中的CTRL +空格为您提供了正则表达式写入的各种建议。 (我恐怕按键,下来的建议列表,删除您的输入在文本框中。刺激小bug)


In eclipse, is it possible to use the matched search string as part of the replace string when performing a regular expression search and replace?

Basically, I want to replace all occurrences of

variableName.someMethod()

with:

((TypeName)variableName.someMethod())

Where variableName can be any variable name at all.

In sed I could use something like:

s/[a-zA-Z]+\.someMethod\(\)/((TypeName)&)/g

That is, & represents the matched search string. Is there something similar in Eclipse?

Thanks!

解决方案

Yes, "( )" captures a group. you can use it again with $i where i is the i'th capture group.

so:

search: (\w+\.someMethod\(\))
replace: ((TypeName)$1)

hint: CTRL + space in the textboxes gives you all kinds of suggestions for regular expression writing. (I'm afraid the down key, to go down the list of suggestions, does delete your input in the textbox. Irritating little bug)

这篇关于Eclipse,正则表达式搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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