Try to change your regex to
String REGEX = "1\\n2";
So it escapes the \n
Example:
public static void main(String[] args) {
String REGEX = "1\n2";
Pattern p = Pattern.compile(REGEX, Pattern.DOTALL);
Matcher m = p.matcher("test1\n2test");
String newText = m.replaceAll("abcd");
System.out.println(newText);
}
O/P:
testabcdtest
Or even simply
String newText = "test1\n2test".replaceAll("1\n2", "abcd");
O/P
testabcdtest