@Udf(description = "Returns a new string with all matches of regexp in str replaced with newStr")
  public String regexpReplace(
      @UdfParameter(
          description = "The source string. If null, then function returns null.") final String str,
      @UdfParameter(
          description = "The regexp to match."
              + " If null, then function returns null.") final String regexp,
      @UdfParameter(
          description = "The string to replace the matches with."
              + " If null, then function returns null.") final String newStr) {
    if (str == null || regexp == null || newStr == null) {
      return null;
    }

    try {
      return str.replaceAll(regexp, newStr);
    } catch (PatternSyntaxException e) {
      throw new KsqlFunctionException("Invalid regular expression pattern: " + regexp, e);
    }
  }
@Test
  public void shouldReplace() {
    assertThat(udf.regexpReplace("foobar", "foo", "bar"), is("barbar"));
    assertThat(udf.regexpReplace("foobar", "fooo", "bar"), is("foobar"));
    assertThat(udf.regexpReplace("foobar", "o", ""), is("fbar"));
    assertThat(udf.regexpReplace("abc", "", "n"), is("nanbncn"));

    assertThat(udf.regexpReplace("foobar", "(foo|bar)", "cat"), is("catcat"));
    assertThat(udf.regexpReplace("foobar", "^foo", "cat"), is("catbar"));
    assertThat(udf.regexpReplace("foobar", "^bar", "cat"), is("foobar"));
    assertThat(udf.regexpReplace("barbar", "bar$", "cat"), is("barcat"));
    assertThat(udf.regexpReplace("aababa", "ab", "xy"), is("axyxya"));
    assertThat(udf.regexpReplace("aababa", "(ab)+", "xy"), is("axya"));
  }