sub(pattern, repl, string[, count=0]) -> string
Return the string obtained by replacing the leftmost
non-overlapping occurrences of pattern in string by the
replacement repl. If the pattern isn't found, string is returned
unchanged. repl can be a string or a function; if a function, it
is called for every non-overlapping occurrence of pattern. The
function takes a single match object argument, and returns the
replacement string.
The pattern may be a string or a regex object; if you need to
specify regular expression flags, you must use a regex object, or
use embedded modifiers in a pattern; e.g.
sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'.
The optional argument count is the maximum number of pattern
occurrences to be replaced; count must be a non-negative integer,
and the default value of 0 means to replace all occurrences.
Definition at line 156 of file pre.py.
157 def sub(pattern, repl, string, count=0):
158 """sub(pattern, repl, string[, count=0]) -> string
160 Return the string obtained by replacing the leftmost
161 non-overlapping occurrences of pattern in string by the
162 replacement repl. If the pattern isn't found, string is returned
163 unchanged. repl can be a string or a function; if a function, it
164 is called for every non-overlapping occurrence of pattern. The
165 function takes a single match object argument, and returns the
168 The pattern may be a string or a regex object; if you need to
169 specify regular expression flags, you must use a regex object, or
170 use embedded modifiers in a pattern; e.g.
171 sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'.
173 The optional argument count is the maximum number of pattern
174 occurrences to be replaced; count must be a non-negative integer,
175 and the default value of 0 means to replace all occurrences.
178 if type(pattern) == type(
''):
179 pattern = _cachecompile(pattern)
180 return pattern.sub(repl, string, count)