Here you can find the source of removeAll(final StringBuilder s, final Pattern start, final Pattern end)
public static StringBuilder removeAll(final StringBuilder s, final Pattern start, final Pattern end)
//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 StringBuilder removeAll(final StringBuilder s, final Pattern start, final Pattern end) { while (remove(s, start, end, true) != null) ;//w w w. j ava 2 s . c om return s; } 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; } 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; } }