@@ -279,25 +279,47 @@ The special characters are:
279279 ``[]()[{}] `` will match a right bracket, as well as left bracket, braces,
280280 and parentheses.
281281
282- .. .. index:: single: --; in regular expressions
283- .. .. index:: single: &&; in regular expressions
284- .. .. index:: single: ~~; in regular expressions
285- .. .. index:: single: ||; in regular expressions
286-
287- * Support of nested sets and set operations as in `Unicode Technical
288- Standard #18 `_ might be added in the future. This would change the
289- syntax, so to facilitate this change a :exc: `FutureWarning ` will be raised
290- in ambiguous cases for the time being.
291- That includes sets starting with a literal ``'[' `` or containing literal
292- character sequences ``'--' ``, ``'&&' ``, ``'~~' ``, and ``'||' ``. To
293- avoid a warning escape them with a backslash.
282+ .. index ::
283+ single: --; in regular expressions
284+ single: &&; in regular expressions
285+ single: ||; in regular expressions
286+
287+ * A character set may contain a nested set written in square brackets, and
288+ two sets may be combined with a set operator, as in `Unicode Technical
289+ Standard #18 `_:
290+
291+ * ``[A--B] `` (*difference *) matches a character that is in *A * but not
292+ in *B *; for example ``[a-z--[aeiou]] `` matches an ASCII lowercase
293+ consonant.
294+ * ``[A&&B] `` (*intersection *) matches a character that is in both *A *
295+ and *B *; for example ``[\w&&[a-z]] `` matches an ASCII lowercase letter.
296+ * ``[A||B] `` (*union *) matches a character that is in *A * or in *B *; this
297+ is the same as listing the members of both sets in a single set, but
298+ allows combining nested sets.
299+
300+ Operators have no precedence and are applied from left to right. To
301+ group, write a nested set as the operand after an operator, as in
302+ ``[a-z--[aeiou]] ``. A leading ``'^' `` complements the whole result.
303+ A ``'[' `` begins a nested set only immediately after a set operator;
304+ anywhere else -- including at the start of a character set -- it is an
305+ ordinary character, so existing patterns keep their meaning. Escape it
306+ as ``'\[' `` to include a literal ``'[' `` right after an operator.
294307
295308 .. _Unicode Technical Standard #18 : https://unicode.org/reports/tr18/
296309
310+ .. note ::
311+
312+ Symmetric difference (``A~~B ``) is not yet supported; a literal ``'~~' ``
313+ in a character set still raises a :exc: `FutureWarning `.
314+
297315 .. versionchanged :: 3.7
298316 :exc: `FutureWarning ` is raised if a character set contains constructs
299317 that will change semantically in the future.
300318
319+ .. versionchanged :: next
320+ Added support for nested sets and the set operators ``-- ``, ``&& ``
321+ and ``|| ``.
322+
301323.. index :: single: | (vertical bar); in regular expressions
302324
303325``| ``
0 commit comments