Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43ab0cd

Browse files
committed
[Bug #990792] Mention that repl can be a callable
1 parent 5d9c303 commit 43ab0cd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/sre.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ def search(pattern, string, flags=0):
139139
def sub(pattern, repl, string, count=0):
140140
"""Return the string obtained by replacing the leftmost
141141
non-overlapping occurrences of the pattern in string by the
142-
replacement repl"""
142+
replacement repl. repl can be either a string or a callable;
143+
if a callable, it's passed the match object and must return
144+
a replacement string to be used."""
143145
return _compile(pattern, 0).sub(repl, string, count)
144146

145147
def subn(pattern, repl, string, count=0):
146148
"""Return a 2-tuple containing (new_string, number).
147149
new_string is the string obtained by replacing the leftmost
148150
non-overlapping occurrences of the pattern in the source
149151
string by the replacement repl. number is the number of
150-
substitutions that were made."""
152+
substitutions that were made. repl can be either a string or a
153+
callable; if a callable, it's passed the match object and must
154+
return a replacement string to be used."""
151155
return _compile(pattern, 0).subn(repl, string, count)
152156

153157
def split(pattern, string, maxsplit=0):

0 commit comments

Comments
 (0)