Commit 27607290 authored by Ezio Melotti's avatar Ezio Melotti

#13219: merge with 3.2.

parents 6e7c1554 81231d93
...@@ -161,30 +161,36 @@ The special characters are: ...@@ -161,30 +161,36 @@ The special characters are:
raw strings for all but the simplest expressions. raw strings for all but the simplest expressions.
``[]`` ``[]``
Used to indicate a set of characters. Characters can be listed individually, or Used to indicate a set of characters. In a set:
a range of characters can be indicated by giving two characters and separating
them by a ``'-'``. Special characters are not active inside sets. For example, * Characters can be listed individually, e.g. ``[amk]`` will match ``'a'``,
``[akm$]`` will match any of the characters ``'a'``, ``'k'``, ``'m'``, or ``'k'``.
``'m'``, or ``'$'``; ``[a-z]`` will match any lowercase letter, and
``[a-zA-Z0-9]`` matches any letter or digit. Character classes such * Ranges of characters can be indicated by giving two characters and separating
as ``\w`` or ``\S`` (defined below) are also acceptable inside a them by a ``'-'``, for example ``[a-z]`` will match any lowercase ASCII letter,
range, although the characters they match depends on whether ``[0-5][0-9]`` will match all the two-digits numbers from ``00`` to ``59``, and
:const:`ASCII` or :const:`LOCALE` mode is in force. If you want to ``[0-9A-Fa-f]`` will match any hexadecimal digit. If ``-`` is escaped (e.g.
include a ``']'`` or a ``'-'`` inside a set, precede it with a ``[a\-z]``) or if it's placed as the first or last character (e.g. ``[a-]``),
backslash, or place it as the first character. The pattern ``[]]`` it will match a literal ``'-'``.
will match ``']'``, for example.
* Special characters lose their special meaning inside sets. For example,
You can match the characters not within a range by :dfn:`complementing` the set. ``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
This is indicated by including a ``'^'`` as the first character of the set; ``'*'``, or ``')'``.
``'^'`` elsewhere will simply match the ``'^'`` character. For example,
``[^5]`` will match any character except ``'5'``, and ``[^^]`` will match any * Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
character except ``'^'``. inside a set, although the characters they match depends on whether
:const:`ASCII` or :const:`LOCALE` mode is in force.
Note that inside ``[]`` the special forms and special characters lose
their meanings and only the syntaxes described here are valid. For * Characters that are not within a range can be matched by :dfn:`complementing`
example, ``+``, ``*``, ``(``, ``)``, and so on are treated as the set. If the first character of the set is ``'^'``, all the characters
literals inside ``[]``, and backreferences cannot be used inside that are *not* in the set will be matched. For example, ``[^5]`` will match
``[]``. any character except ``'5'``, and ``[^^]`` will match any character except
``'^'``. ``^`` has no special meaning if it's not the first character in
the set.
* To match a literal ``']'`` inside a set, precede it with a backslash, or
place it at the beginning of the set. For example, both ``[()[\]{}]`` and
``[]()[{}]`` will both match a parenthesis.
``'|'`` ``'|'``
``A|B``, where A and B can be arbitrary REs, creates a regular expression that ``A|B``, where A and B can be arbitrary REs, creates a regular expression that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment