@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(expected = KsqlFunctionException.class)
  public void shouldThrowExceptionOnBadPattern() {
    udf.regexpReplace("foobar", "(()", "bar");
  }