Monti Chandra
Monti Chandra

Reputation: 442

How to create a String with containing escape sequences in java without using StringEscapeUtils Class?

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

Can anyone help me in this. Thanks in advance.

Upvotes: 1

Views: 96

Answers (1)

Christian Fries
Christian Fries

Reputation: 16952

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.

Upvotes: 1

Related Questions