import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main
{
   static void printMatch(String regex, String str, int... groups)
   {
      System.out.println("String = " + str);
      System.out.println("Regex = " + regex);
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(str);
      while (m.find())
         for (int i: groups)
            System.out.println("Group " + i + " = " + m.group(i));
      System.out.println();
   }

   public static void main(String[] args) throws Exception
   {
      String regex = "echo[\\t ]+\".*?(?<!\\\\)\"";
      String str = "some other stuff echo \"This will not \\\" work\" some other stuff";
      printMatch(regex, str, 0);
   }
}