protected String[] complexSplit(String line, Pattern p) {

    ArrayList<String> list = new ArrayList<String>();
    Matcher m = p.matcher(line);
    // For each field
    while (m.find()) {
      String match = m.group();
      if (match == null) {
        break;
      }
      if (match.length() == 0) {
        match = null;
      } else {
        if (stripSeparatorPrefix.matcher(match).find()) {
          match = match.substring(1);
        }
        if (stripQuotePrefix.matcher(match).find()) {
          match = match.substring(1);
        }
        if (stripQuotePostfix.matcher(match).find()) {
          match = match.substring(0, match.length() - 1);
        }
      }
      list.add(match);
    }
    return list.toArray(new String[1]);
  }
Split the line based on a complex regex pattern.

@param line
         the current row
@param p
         the pattern for matching fields in the row
@return List of Strings - not including the separator in them
serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java