Multiline search replace with regexp in Eclipse

2020-03-09 07:10发布

Eclipse regexp search works pretty well, so for example in search box I have this:

(?s)(myMethod.*?;)\}\);

Now I want to copy multiline text in the IDE and in replace box, for example I want to paste \1PASTE_MULTILINE_TEXT_HERE. However Eclipse does not allow me to directly copy-paste multiline text without manually inserting newline characters.

In Vim (Gvim, Macvim) it works perfectly well, keeping all the spaces; how can I do the same thing in Eclipse?

2条回答
够拽才男人
2楼-- · 2020-03-09 08:02

For searching multiple lines in Eclipse, you must use the 's' parameter in search expression:

(?s)someExpressionToMatchInAnyLine

For replacing with multiple lines exp you must use \R i.e:

line1\Rline2\Rline3

This will replace the matched exp with:
line1
line2
line3

查看更多
一夜七次
3楼-- · 2020-03-09 08:17

Generally, the approach I've taken to doing this sort of thing is to type out what I want to use as a replacement, select that, open up the Find/Replace dialog, and copy the contents of the Find text box. I proceed from there and paste what I copied into the Replace text box. There is still a little work to be done (removing backslashes from in front of regex special characters that don't apply in the Replace box), but it gives me a hand up.

查看更多
登录 后发表回答