code: def subfn(pattern, format, string, *args, **kwargs):  # noqa A002
      
  
      flags = args[4] if len(args) > 4 else kwargs.get('flags', 0)
      is_replace = _is_replace(format)
      is_string = isinstance(format, (str, bytes))
      if is_replace and not format.use_format:
          raise ValueError("Compiled replace is not a format object!")
  
      pattern = compile_search(pattern, flags)
      rflags = FORMAT if is_string else 0
      return _regex.subn(
          pattern, (compile_replace(pattern, format, flags=rflags) if is_replace or is_string else format), string,
          *args, **kwargs
      )
docs: Wrapper for `subfn`.