code: private static int indexOfNextDelimiter(String script, int indexOfPreviousDelimiter)
     {
        if (indexOfPreviousDelimiter < 0 || script.length() <= indexOfPreviousDelimiter)
        {
           return -1;
        }
        final char delim = script.charAt(indexOfPreviousDelimiter);
        if (delim == '\\')
        {
           throw new IllegalArgumentException("invalid delimiter '\\' in sed script: " + script);
        }
        int index = indexOfPreviousDelimiter;
        do
        {
           index = script.indexOf(delim, index + 1);
        }
        while (index >= 0 && isEscaped(script, index));
        return index;
     }
docs: Returns the index of the next delimiter in the given sed script. The
  character at {@code indexOfPreviousDelimiter} is taken as delimiter. The
  method handles escaped delimiters and returns -1 if no further delimiter
  is found.
  
  @param script
  the script to analyze
  @param indexOfPreviousDelimiter
  the index of the previous delimiter
  @return the index of the next delimiter after
  {@code indexOfPreviousDelimiter}, or -1 if no further delimiter
  exists of if {@code indexOfNextDelimiter < 0}