I am looking for a regular expression that replaces any Bin a string that is not surrounded by Aand Z.
Please note that there can be many inside and outside sequences B, starting with Aand ending with Z, but I only want to replace those that are outside.
In other words: what kind of Regex is required to pass the next JUnit test?
@Test
public void testReplaceBnotBetweenAandZ() throws Exception {
String str = "U-B-V-B-A-B-C-B-Z-W-A-B-Z-B-U";
String repl = str.replaceAll(**#REGEX#**, "x");
Assert.assertEquals("U-x-V-x-A-B-C-B-Z-W-A-B-Z-x-U", repl);
}
The real use case is to replace any &HTML (X) line characters that are not in the CDATA section. ( B= &, A= <![CDATA[and Z= ]]>).
Thank!
source
share