如何在Eclipse中一起搜索和替换2行?
问题描述:
我想通过Eclipse搜索以下两行的多个文件:
I would like to search multiple files via eclipse for the following 2 lines:
@Length(max = L_255)
private String description;
并用以下两个替换它们:
and replace them with these two:
@Length(max = L_255, message="{validator.description.len}")
private String description;
答
在Eclipse中,默认情况下,搜索是多行的使用正则表达式:
Search are multi-line by default in Eclipse when you are using regex:
(\@Length\(max = L_255)\)([\r\n\s]+private)
我想添加私有字符串描述;
I would like to add "private String description;"
(\@Length\(max = L_255)\)([\r\n\s]+private\s+?String\s+description\s*?;)
替换为:
\1, message="{validator.description.len}")\2
它在由触发的文件搜索中非常有效CTRL - H 。
如 Tika 的 answer ,您可以直接复制在 保留文本字段:Eclipse将为您将这些行转换为正则表达式。
As mentioned in Tika's answer, you can directly copy the two lines selected in the "Containing Text" field: those lines will be converted as a regexp for you by Eclipse.