python / python/cpython

Support set operations in regular expression character classes

Open
#152,100 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-regex type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Implement the set operations of Unicode Technical Standard #18 RL1.3 in re character classes, together with nested sets.

gh-74534 added FutureWarnings in Python 3.7 for the ambiguous constructs (--, &&, ~~, ||, and a leading [) as preparation for this syntax; this issue turns them into operators.

Two character sets are combined by an operator, where an operand may be a nested set in brackets:

  • [A--B] — difference: a character in A but not in B.
  • [A&&B] — intersection: a character in both A and B.
  • [A||B] — union: a character in A or B.
  • [A~~B] — symmetric difference: a character in A or B but not both.

Operators have no precedence and apply left to right; nested sets are used to group. A leading ^ complements the whole result.

For example, [a-z--[aeiou]] matches an ASCII lowercase consonant and [\w&&[a-z]] matches an ASCII lowercase letter.

Linked PRs
  • gh-152153
  • gh-152154
  • gh-152214
  • gh-153022

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Python's re character-class handling and Unicode Technical Standard #18 RL1.3. Confirm completion against the listed difference, intersection, union, symmetric-difference, nesting, left-to-right, and complement examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.