@Test
public void testExtract() throws Exception {

  Pattern pattern = Pattern.compile("(?<=(\\?|&)q=).*?(?=&|$)");
  String line = "127.0.0.1 -  -  [24/05/2010:01:19:22 +0000] \"GET /solr/select?q=import statement&start=1 HTTP/1.1\" 200 37571";
  String res = RegexUtils.extract(line, pattern, Collections.<Integer>emptyList(), " ", RegexUtils.IDENTITY_TRANSFORMER);
  assertEquals(res, "import statement", res);
  for (int i = 0; i < TEST_STRS.length; i++) {
    String testStr = TEST_STRS[i];
    res = RegexUtils.extract(testStr, pattern, Collections.<Integer>emptyList(), " ", new URLDecodeTransformer());
    assertEquals(GOLD[i], res);
  }
  pattern = Pattern.compile("((?<=(\\?|&)q=)(.*?)(?=(&|$))|(?<=((\\?|&)start=))(\\d+))");
  res = RegexUtils.extract(line, pattern, Collections.<Integer>emptyList(), " ", RegexUtils.IDENTITY_TRANSFORMER);
  assertEquals(res, "import statement 1", res);
  pattern = Pattern.compile("(start=1) HTTP");
  Collection<Integer> groupsToKeep = Lists.newArrayList();
  groupsToKeep.add(1);
  res = RegexUtils.extract(line, pattern, groupsToKeep, " ", RegexUtils.IDENTITY_TRANSFORMER);
  assertEquals(res, "start=1", res);
}