void () { String source = """ class MyClass { private String b;// comment public void foo() { } }"""; String search = "class 'Class {\n '_Content*\n}"; String replace = """ class $Class$ { void x() {} $Content$ void bar() {} }"""; String expectedResult = """ class MyClass { void x() {} private String b;// comment public void foo() { } void bar() {} }"""; assertEquals(expectedResult, replace(source, search, replace, true)); }