MCPcopy Index your code
hub / github.com/RustPython/RustPython / subn

Function subn

Lib/re/__init__.py:211–238  ·  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

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

Callers

nothing calls this directly

Calls 4

lenFunction · 0.85
_compileFunction · 0.70
warnMethod · 0.45
subnMethod · 0.45

Tested by

no test coverage detected