mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
This commit is contained in:
parent
387235085c
commit
dba903993a
63 changed files with 445 additions and 409 deletions
|
@ -1115,19 +1115,19 @@ which can be either a string or a function, and the string to be processed.
|
|||
Here's a simple example of using the :meth:`sub` method. It replaces colour
|
||||
names with the word ``colour``::
|
||||
|
||||
>>> p = re.compile( '(blue|white|red)')
|
||||
>>> p.sub( 'colour', 'blue socks and red shoes')
|
||||
>>> p = re.compile('(blue|white|red)')
|
||||
>>> p.sub('colour', 'blue socks and red shoes')
|
||||
'colour socks and colour shoes'
|
||||
>>> p.sub( 'colour', 'blue socks and red shoes', count=1)
|
||||
>>> p.sub('colour', 'blue socks and red shoes', count=1)
|
||||
'colour socks and red shoes'
|
||||
|
||||
The :meth:`subn` method does the same work, but returns a 2-tuple containing the
|
||||
new string value and the number of replacements that were performed::
|
||||
|
||||
>>> p = re.compile( '(blue|white|red)')
|
||||
>>> p.subn( 'colour', 'blue socks and red shoes')
|
||||
>>> p = re.compile('(blue|white|red)')
|
||||
>>> p.subn('colour', 'blue socks and red shoes')
|
||||
('colour socks and colour shoes', 2)
|
||||
>>> p.subn( 'colour', 'no colours at all')
|
||||
>>> p.subn('colour', 'no colours at all')
|
||||
('no colours at all', 0)
|
||||
|
||||
Empty matches are replaced only when they're not adjacent to a previous match.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue