public String toRegex() {
    return toRegex(false, false);
  }
@Test
  public void asRegex() {
    {
      FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
          context);
      String regex = fnp.toRegex();
      assertEquals("foo-" + FileFinder.regexEscapePath("\\d{4}\\.\\d{2}\\.\\d{2}") + "-" + FileFinder.regexEscapePath("\\d+") + ".txt", regex);
    }
    {
      FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd'T'}-%i.txt",
          context);
      String regex = fnp.toRegex();
      assertEquals("foo-" + FileFinder.regexEscapePath("\\d{4}\\.\\d{2}\\.\\d{2}T") + "-" + FileFinder.regexEscapePath("\\d+") + ".txt", regex);
    }
  }