Eclipse regex and newline bug

This is more of a case of just letting everyone know as to prevent head butting against the wall and going back through RegEx books.

I was trying to replace a load of commas with newlines via the find/replace using regex a task I thought was simple:

Find: "," Replace with: "\n"

All that happend was an "n" being inserted. I tried"

Find: "," Replace with: "\\n"

This inserted "\n".

Posted: 03-Nov-2006

View: 9468

Permalink: here

Comments

Just found this post on Google and wanted to say thanks. I switched to Eclipse from jEdit and have been wondering what the hell I've been doing wrong with my newline regexps!! Luckily I haven't uninstalled jEdit yet ;)

#1 Dave
06/Jun/07 7:16 PM

Eclipse 3.2.2 + QuickRex plugin
Haven't noticed this bug. \n is \n as it should be.

Also, the find-dialog helper for regex notation is really helpful. Dunno if it's there by default or was added by QuickRex.

#2 anttipi
18/Sep/07 11:21 PM

I found a little work-around. To get a new-line character, type the following in Eclipse:
--snip--
c
c
--snip--
(if the above doesn't format correctly for some reason, it is just a character on one line, and a character on the line below it)

Copy the two characters into the "Replace with" box and you'll now see something like:
c{weird character}c
Now, just replace the two c's with your own regexp stuff. The weird character will work as a newline.

#3 Juan
26/Oct/07 3:24 AM

As this is the second google result for this problem and I do not want to register in any website only to comment on that "bug", I post here another work-around for this (the previous one does not seem to work).

If the searched string is on a single line, instead of writing for example "^someRegExp$", write instead "^someRegExp([\n\r]+)" and use the last capturing group in the replacement string as the new line marker (for example: "my$1multline$1string").

#4 Enisseo
07/Jul/08 3:46 AM