Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Find/Replace Whole Line With Regex

I'm using Eclipse's Find/Replace to format some sql code as a Java string. I want to place each line of the sql query between quotation marks and add a line break at the end.

Here is what I put in the find field:

(.*)

This is what I put in the replace field

\t\t+ "\1\\n"

Here's simple example (my actual sql query is about 200 lines)

SELECT *

FROM User
WHERE User.Id = 1232164

And this is what I expect to see after

    + "SELECT *\n"
    + "\n"
    + "FROM User\n"
    + "WHERE User.Id = 1232164\n"

However, the Find fails when it encounters the blank line it says there are no more matching results and terminates (or jumps to the top of the file if the 'Wrapped Search' option is marked)

I also tried using the following in the find regex

^(.*)
^(.*)$

with the same results

Anyone know what I'm doing wrong or is this perhapse a bug in Eclipse.

For what its worth, it works fine in Emacs as I originally wrote it.

like image 826
Craig Avatar asked Oct 10 '12 08:10

Craig


1 Answers

It strikes me as a bug in Eclipse. Nevertheless, I've achieved your desired result (in Eclipse Juno) by using a search pattern:

(.*)\R

and a replacement string:

\t\t+ "\1\\n"\R

Note that \R is a special Eclipse pattern that matches any form of line delimiter, when searching. When replacing, it inserts the default line delimiter for the document.

like image 122
Duncan Jones Avatar answered Sep 19 '22 09:09

Duncan Jones