StringUtil { public static String[] getAllSubstrings(final String inputString, final String startingWith, final String endingWith) { if (!inputString.contains(startingWith) || !inputString.contains(endingWith)) { return new String[0]; } final int inputStringLength = inputString.length(); final int endingWithLength = endingWith.length(); final int maxArrayLength = inputStringLength / (startingWith.length() + endingWithLength); if (maxArrayLength == 0) { return new String[0]; } final String[] maxSubstrings = new String[maxArrayLength]; int startSearchFromIndex = 0; int count = 0; do { final int startIndex = inputString.indexOf(startingWith, startSearchFromIndex); if (!((startIndex + 1) < inputStringLength)) { break; } final int indexOfEndingWith = inputString.indexOf(endingWith, startIndex + 1); if (startIndex < 0 || indexOfEndingWith < 0) { break; } final int endIndex = indexOfEndingWith + endingWithLength; startSearchFromIndex = endIndex; if ((startIndex > endIndex)) { startSearchFromIndex = inputStringLength; } else { maxSubstrings[count] = inputString.substring(startIndex, endIndex); count++; } } while (startSearchFromIndex < inputStringLength); final String[] substrings = new String[count]; System.arraycopy(maxSubstrings, 0, substrings, 0, count); return substrings; } private  StringUtil(); static String convertToSingleSpace(final String input); static String getFirstSubstring(final String inputString,
            final String startingWith, final String endingWith); static String getFirstSubstring(final String inputString,
            final String startingWith, final String endingWith,
            final int searchFromIndex); static String[] getAllSubstrings(final String inputString,
            final String startingWith, final String endingWith); static int startIndexOf(final String inputString,
            final String startingWith, final String endingWith); static int endIndexOf(final String inputString,
            final String startingWith, final String endingWith); static int startIndexOf(final String inputString,
            final String startingWith, final String endingWith,
            final int searchFromIndex); static int endIndexOf(final String inputString,
            final String startingWith, final String endingWith,
            final int searchFromIndex); static int[] startIndexAndEndIndexOf(final String inputString,
            final String startingWith, final String endingWith); static int[] startIndexAndEndIndexOf(final String inputString,
            final String startingWith, final String endingWith,
            final int searchFromIndex); static int[][] startAndEndIndexesOf(final String inputString,
            final String startingWith, final String endingWith); static String[] cloneArray(final String[] inputArray); static boolean isEqual(final String... strings); static boolean isEqual(final String string1, final String string2); static boolean startsWithWhitespace(final String value); static boolean endsWithWhitespace(final String value); static String[] split(final String string, final char delim); static String[] splitBySpace(final String string); static String[] splitByComma(final String string); static String[] splitBySemicolon(final String string); static String[] splitByColon(final String string); static boolean endsWithSpace(final String string); static boolean endsWithColon(final String string); static boolean startsWithSpace(final String string); static boolean containsSpace(final String string); static boolean containsWhitespace(final String string); static boolean containsMinus(final String string); static boolean containsPlus(final String string); static String join(final char delimiter, final char prefix,
            final char suffix, final String... items); static String join(final char delimiter, final String... items); static String join(final char delimiter,
            final Collection<String> items); static boolean isBlank(final String s); static String strip(final String s);  }
@Test public void testGetAllSubstrings() { final String[] allSubstrings = StringUtil.getAllSubstrings( "dfsf rgb(7, 8, 9, 1)rgb(3, 5, 6)", "rgb(", ")"); assertEquals("rgb(7, 8, 9, 1)", allSubstrings[0]); assertEquals("rgb(3, 5, 6)", allSubstrings[1]); assertEquals(2, allSubstrings.length); }