@Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    String s = getStringValue(arguments, 0, converters);
    if (s == null) {
      return null;
    }

    String regex;
    if (isRegexConst) {
      regex = regexConst;
    } else {
      regex = getStringValue(arguments, 1, converters);
    }
    if (regex == null) {
      return null;
    }

    if (regex.length() == 0) {
      if (!warned) {
        warned = true;
        LOG.warn(getClass().getSimpleName() + " regex is empty. Additional "
            + "warnings for an empty regex will be suppressed.");
      }
      output.set(false);
      return output;
    }

    if(!useGoogleRegexEngine){
      Pattern p;
      if (isRegexConst) {
        p = patternConst;
      } else {
        p = Pattern.compile(regex);
      }

      Matcher m = p.matcher(s);
      output.set(m.find(0));
      return output;
    }else{
      com.google.re2j.Pattern patternR2j;
      if (isRegexConst) {
        patternR2j = patternConstR2j;
      } else {
        patternR2j = com.google.re2j.Pattern.compile(regex);
      }

      com.google.re2j.Matcher m = patternR2j.matcher(s);
      output.set(m.find(0));
      return output;
    }
  }
UDF to extract a specific group identified by a java regex. Note that if a
regexp has a backslash ('\'), then need to specify '\\' For example,
regexp_extract('100-200', '(\\d+)-(\\d+)', 1) will return '100'
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRegExp.java