How to search and replace 2 lines (together) in Eclipse?

后端 未结 5 1981
青春惊慌失措
青春惊慌失措 2020-12-07 22:19

I would like to search multiple files via eclipse for the following 2 lines:

@Length(max = L_255)
private String description;

and replace t

5条回答
  •  执念已碎
    2020-12-07 22:53

    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*?;)
    

    replaced by:

    \1, message="{validator.description.len}")\2
    

    It works perfectly in a File Search triggered by a CTRL-H.

    Eclipse multi-line search

    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.

提交回复
热议问题