Raw Strings in Java - for regex in particular. Multiline strings

Debajit picture Debajit · Aug 10, 2009 · Viewed 41.3k times · Source

Is there any way to use raw strings in Java (without escape sequences)?

(I'm writing a fair amount of regex code and raw strings would make my code immensely more readable)

I understand that the language does not provide this directly, but is there any way to "simulate" them in any way whatsoever?

Answer

Dread picture Dread · Oct 20, 2010

This is a work-around if you are using eclipse. You can automatically have long blocks of text correctly multilined and special characters automatically escaped when you paste text into a string literal

"-paste here-";

if you enable that option in window→preferences→java→Editor→Typing→"Escape text when pasting into a string literal"