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)
| 211 | sub.__text_signature__ = '(pattern, repl, string, count=0, flags=0)' |
| 212 | |
| 213 | def 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) |
| 241 | subn.__text_signature__ = '(pattern, repl, string, count=0, flags=0)' |
| 242 | |
| 243 | def split(pattern, string, *args, maxsplit=_zero_sentinel, flags=_zero_sentinel): |