EmbeddedFlagUtil { public String embedFlags(String regex, int flags) { if (flags == 0) { return regex; } else { return "(?" + mapFlagsToEmbeddedFlags(flags) + ":" + regex + ")"; } }  String embedFlags(String regex, int flags);  }
@Test public void testEmbedFlags() throws Exception { assertEquals("(?im:abc)", util.embedFlags("abc", Pattern.CASE_INSENSITIVE ^ Pattern.MULTILINE)); assertEquals("abc", util.embedFlags("abc", 0)); }
@Test public void testEmbedFlags_differentFlags() throws Exception { String regex1 = "ABC"; String regex2 = "XYZ"; String regex = "(" + util.embedFlags(regex1, 0) + ")|(" + util.embedFlags(regex2, Pattern.CASE_INSENSITIVE) + ")"; assertEquals(true, "ABC".matches(regex)); assertEquals(false, "abc".matches(regex)); assertEquals(true, "XYZ".matches(regex)); assertEquals(true, "xyz".matches(regex)); }