int lastlength = 0; // used in newline trimming to see if one block immediately follows the previous
while (matcher.find())
{
// BEGIN: newline trimming
String after = matcher.group(3); // contents after tag
if (lastlength == 0 || fileText.charAt(matcher.start() - 1) == '\n') {
after = after.replaceFirst("^\\r?\\n", "");
}
lastlength = after.length();
// END: newline trimming
if (matcher.group(1).toUpperCase().equals("BEGIN"))