Here you can find the source of remove(final StringBuilder s, final Pattern start, final Pattern end, final boolean includeEnd)
public static String remove(final StringBuilder s, final Pattern start, final Pattern end, final boolean includeEnd)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String remove(final StringBuilder s, final Pattern start, final Pattern end, final boolean includeEnd) { final Matcher startMatcher = start.matcher(s); if (!startMatcher.find()) { return null; }//from w w w . j a v a2s .c o m final int startIndex = startMatcher.start(); final Matcher endMatcher = end.matcher(s); endMatcher.region(startMatcher.end(), s.length()); final int endIndex; if (endMatcher.find()) { endIndex = includeEnd ? endMatcher.end() : endMatcher.start(); } else { endIndex = s.length(); } final String result = s.substring(startIndex, endIndex); s.replace(startIndex, endIndex, ""); return result; } }