How can one search and replace 2 lines (together) via 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;
Search are multi-line by default in Eclipse when you are using regex:
(@Length(max = L_255))([rns]+private)
I would like to add "private String description;"
(@Length(max = L_255))([rns]+privates+?Strings+descriptions*?;)
replaced by:
1, message="{validator.description.len}")2
It works perfectly in a File Search triggered by a CTRL-H.
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.
Another tip on how to get the regex for a selected block. Open one of the files that contains the multiple lines (multiline) to search or replace. Click Ctrl+F and select "Regular expression". Close the Find/Replace window. Select the block you need and click again Ctrl+F to open the Find/Replace window. Now in the Find text box you have the regular expression that exactly matches your selection block.
(I discovered this, only after creating manually a regexp for very long block :)
CTRL+H does take two lines if you use regexp (and you don't have to write the regexp by yourself, eclipse does that for you).
上一篇: Eclipse的深色配色方案