code: public static String extractSubstring(
          String str,
          String open,
          String close,
          char escape,
          boolean cleanEscape)
      {
          int i;
          StringBuffer buf = new StringBuffer();
          int len = str.length();
          for (i = 0; i < len; i++) {
              if (str.startsWith(open, i)) {
                  i += open.length();
                  break;
              }
          }
  
          boolean escaped = false;
          for (; i < len; i++) {
              if (escaped) {
                  char ch = str.charAt(i);
                  buf.append(ch);
                  escaped = false;
              } else {
                  if (str.startsWith(close, i)) {
                      break;
                  }
                  char ch = str.charAt(i);
                  escaped = ch == escape;
                  if (!escaped || !cleanEscape) {
                      buf.append(ch);
                  }
              }
          }
  
          return buf.toString();
      }
docs: Extracts and returns a substring of the given string starting from the
  given open sequence and finishing by the specified close sequence. This
  method unescapes all symbols prefixed by the given escape symbol.
  
  @param str from this string the substring framed by the specified open
  and close sequence will be returned
  @param open the start substring sequence
  @param close the closing substring sequence
  @param escape the escape symbol
  @param cleanEscape indicate if the escaping char has to be removed.
  Useful when the substring use the same escaping that the string.
  @return a substring of the given string starting from the given open
  sequence and finishing by the specified close sequence