@Udf(description = "Splits a string into an array of substrings based on a regexp.")
  public List<String> regexpSplit(
      @UdfParameter(
          description = "The string to be split. If NULL, then function returns NULL.")
      final String string,
      @UdfParameter(
          description = "The regular expression to split the string by. "
              + "If NULL, then function returns NULL.")
      final String regexp) {
    if (string == null || regexp == null) {
      return null;
    }

    // Use Guava version to be compatible with other splitting functions.
    final Pattern p = getPattern(regexp);
    if (regexp.isEmpty() || p.matcher("").matches()) {
      return Arrays.asList(p.split(string));
    } else {
      return Splitter.on(p).splitToList(string);
    }
  }
@Test
  public void shouldSplitAndAddEmptySpacesIfRegexIsFoundInContiguousPositions() {
    assertThat(udf.regexpSplit("A--A", "-"), contains("A", "", "A"));
    assertThat(udf.regexpSplit("z--A--z", "-"), contains("z", "", "A", "", "z"));
    assertThat(udf.regexpSplit("--A--A", "-"), contains("", "", "A", "", "A"));
    assertThat(udf.regexpSplit("A--A--", "-"), contains("A", "", "A", "", ""));

    assertThat(udf.regexpSplit("aababa", "ab"), contains("a", "", "a"));
    assertThat(udf.regexpSplit("aababa", "(ab)+"), contains("a", "a"));
    assertThat(udf.regexpSplit("aabcda", "(ab|cd)"), contains("a", "", "a"));
  }