def subfn(pattern, format, string, count=0, flags=0): # noqa B002
"""Apply `subn` after applying backrefs."""
is_replace = _is_replace(format)
is_string = isinstance(format, (compat.string_type, compat.binary_type))
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 re.subn(
pattern, (compile_replace(pattern, format, flags=rflags) if is_replace or is_string else format),
string, count, flags
)
评论列表
文章目录