1

I want to store "~ s/\n|\s+|.*?=|;//g;" in a string variable.

Can anyone help me in this. Thanks in advance.

carloabelli
  • 4,289
  • 3
  • 43
  • 70
Monti Chandra
  • 432
  • 5
  • 21
  • possible duplicate of [Raw Strings in Java - for regex in particular](http://stackoverflow.com/questions/1256667/raw-strings-in-java-for-regex-in-particular) – user158037 Jul 21 '15 at 14:14

1 Answers1

1

You have to replace \ by \\ in a Java String literal. See https://docs.oracle.com/javase/tutorial/essential/regex/literals.html (at the bottom).

That is

String regExp = "~ s/\\n|\s+|.*?=|;//g;";

should work.

Christian Fries
  • 16,175
  • 10
  • 56
  • 67