MCPcopy Index your code
hub / github.com/python/cpython / subn

Function subn

Lib/re/__init__.py:213–240  ·  view source on GitHub ↗

Return a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or

(pattern, repl, string, *args, count=_zero_sentinel, flags=_zero_sentinel)

Source from the content-addressed store, hash-verified

211sub.__text_signature__ = '(pattern, repl, string, count=0, flags=0)'
212
213def subn(pattern, repl, string, *args, count=_zero_sentinel, flags=_zero_sentinel):
214 """Return a 2-tuple containing (new_string, number).
215 new_string is the string obtained by replacing the leftmost
216 non-overlapping occurrences of the pattern in the source
217 string by the replacement repl. number is the number of
218 substitutions that were made. repl can be either a string or a
219 callable; if a string, backslash escapes in it are processed.
220 If it is a callable, it's passed the Match object and must
221 return a replacement string to be used."""
222 if args:
223 if count is not _zero_sentinel:
224 raise TypeError("subn() got multiple values for argument 'count'")
225 count, *args = args
226 if args:
227 if flags is not _zero_sentinel:
228 raise TypeError("subn() got multiple values for argument 'flags'")
229 flags, *args = args
230 if args:
231 raise TypeError("subn() takes from 3 to 5 positional arguments "
232 "but %d were given" % (5 + len(args)))
233
234 import warnings
235 warnings.warn(
236 "'count' is passed as positional argument",
237 DeprecationWarning, stacklevel=2
238 )
239
240 return _compile(pattern, flags).subn(repl, string, count)
241subn.__text_signature__ = '(pattern, repl, string, count=0, flags=0)'
242
243def split(pattern, string, *args, maxsplit=_zero_sentinel, flags=_zero_sentinel):

Callers

nothing calls this directly

Calls 2

_compileFunction · 0.70
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…