mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
#10713: Improve documentation for \b and \B and add a few tests. Initial patch and tests by Martin Pool.
This commit is contained in:
parent
62417a0354
commit
5a045b9f54
2 changed files with 40 additions and 8 deletions
|
@ -330,16 +330,22 @@ the second character. For example, ``\$`` matches the character ``'$'``.
|
|||
Matches the empty string, but only at the beginning or end of a word.
|
||||
A word is defined as a sequence of Unicode alphanumeric or underscore
|
||||
characters, so the end of a word is indicated by whitespace or a
|
||||
non-alphanumeric, non-underscore Unicode character. Note that
|
||||
formally, ``\b`` is defined as the boundary between a ``\w`` and a
|
||||
``\W`` character (or vice versa). By default Unicode alphanumerics
|
||||
are the ones used, but this can be changed by using the :const:`ASCII`
|
||||
flag. Inside a character range, ``\b`` represents the backspace
|
||||
character, for compatibility with Python's string literals.
|
||||
non-alphanumeric, non-underscore Unicode character. Note that formally,
|
||||
``\b`` is defined as the boundary between a ``\w`` and a ``\W`` character
|
||||
(or vice versa), or between ``\w`` and the beginning/end of the string.
|
||||
This means that ``r'\bfoo\b'`` matches ``'foo'``, ``'foo.'``, ``'(foo)'``,
|
||||
``'bar foo baz'`` but not ``'foobar'`` or ``'foo3'``.
|
||||
|
||||
By default Unicode alphanumerics are the ones used, but this can be changed
|
||||
by using the :const:`ASCII` flag. Inside a character range, ``\b``
|
||||
represents the backspace character, for compatibility with Python's string
|
||||
literals.
|
||||
|
||||
``\B``
|
||||
Matches the empty string, but only when it is *not* at the beginning or end of a
|
||||
word. This is just the opposite of ``\b``, so word characters are
|
||||
Matches the empty string, but only when it is *not* at the beginning or end
|
||||
of a word. This means that ``r'py\B'`` matches ``'python'``, ``'py3'``,
|
||||
``'py2'``, but not ``'py'``, ``'py.'``, or ``'py!'``.
|
||||
``\B`` is just the opposite of ``\b``, so word characters are
|
||||
Unicode alphanumerics or the underscore, although this can be changed
|
||||
by using the :const:`ASCII` flag.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue