/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String s = "This is my \"test\" case\nwith lines\n\\section{new section}\nAnother incorrect test\"\n\\section{next section}\nWith some more \"text\"\n\\subsection{next section}\nWith some more \"text1\"";
		StringBuffer result = new StringBuffer();
		Matcher m = Pattern.compile("(?s)section.*?(?=section|$)").matcher(s);
		while (m.find()) {
			String out = m.group(0).replaceAll("\"([^\"]*)\"", "«$1»");
    		m.appendReplacement(result, Matcher.quoteReplacement(out));
		}
		m.appendTail(result);
		System.out.println(result.toString());

	}
}