code: public static String regex_group(EvaluationContext ctx, Object text, Object pattern, Object groupNum) {
          String _text = Conversions.toString(text, ctx);
          String _pattern = Conversions.toString(pattern, ctx);
          int _groupNum = Conversions.toInteger(groupNum, ctx);
  
          try {
              // check whether we match
              int flags = Pattern.CASE_INSENSITIVE | Pattern.MULTILINE;
              Pattern regex = Pattern.compile(_pattern, flags);
              Matcher matcher = regex.matcher(_text);
  
              if (matcher.find()) {
                  if (_groupNum < 0 || _groupNum > matcher.groupCount()) {
                      throw new RuntimeException("No such matching group " + _groupNum);
                  }
  
                  return matcher.group(_groupNum);
              }
          } catch (PatternSyntaxException ignored) {}
  
          return "";
      }
docs: Tries to match the text with the given pattern and returns the value of matching group