GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `re.IGNORECASE | re.LOCALE`: a negated character set matches the other case · Issue #156444 · python/cpython

re.IGNORECASE | re.LOCALE: a negated character set matches the other case #156444

New issue
Copy link
New issue
Copy link
Closed
Closed
re.IGNORECASE | re.LOCALE: a negated character set matches the other case#156444
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-regextype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on Aug 27, 2026
Issue body actions

Under re.IGNORECASE | re.LOCALE, [bc] matches b'B', but so does [^bc].

import re

W = re.IGNORECASE | re.LOCALE
print(re.fullmatch(rb'[bc]', b'B', W))
print(re.fullmatch(rb'[^bc]', b'B', W))
<re.Match object; span=(0, 1), match=b'B'>
<re.Match object; span=(0, 1), match=b'B'>

Expected: the second line is None, which is what 3.6 and earlier print.

charset_loc_ignore() in Modules/_sre/sre_lib.h tests the whole set once per locale case and returns true if either test matches. For a set carrying NEGATE the negation has to be applied outside that disjunction: b'B' matches because 'B' itself is not in {b, c}, though its lowercase is.

A one-member set escapes this, since it compiles to NOT_LITERAL_LOC_IGNORE and compares against both cases correctly, so [^b] is fine and two members are needed to see it.

IN_LOC_IGNORE and charset_loc_ignore() were added in 3.7 by bpo-30215 (898ff03), which moved locale case folding from compile time to match time. 3.2–3.6 are correct, 3.7 through main are affected.

The set-difference fusion new in 3.16 hits the same limitation from another direction: it rewrites A(?<![B]) into a single NEGATE-bearing set, which then compiles to IN_LOC_IGNORE. See gh-155985 and GH-155993, which avoids the fusion under these flags.

Linked PRs

  • gh-156444: Fix a negated character set with IGNORECASE and LOCALE #156445
  • [3.15] gh-156444: Fix a negated character set with IGNORECASE and LOCALE (GH-156445) #156456
  • [3.14] gh-156444: Fix a negated character set with IGNORECASE and LOCALE (GH-156445) #156457
  • [3.13] gh-156444: Fix a negated character set with IGNORECASE and LOCALE (GH-156445) #156458

Activity

  1. serhiy-storchaka
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-regex
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Aug 27, 2026
  2. serhiy-storchaka
    added a commit that references this issue on Aug 27, 2026

    gh-156444: Fix a negated character set with IGNORECASE and LOCALE (GH…

    6671d27
  3. serhiy-storchaka
    closed this as completedon Aug 27, 2026
  4. serhiy-storchaka
    added 2 commits that reference this issue on Aug 27, 2026

    [3.14] gh-156444: Fix a negated character set with IGNORECASE and LOC…

    9ac4200

    [3.13] gh-156444: Fix a negated character set with IGNORECASE and LOC…

    7e7e88f
  5. clin1234
    added a commit that references this issue on Aug 27, 2026

    pythongh-156444: Fix a negated character set with IGNORECASE and LOCA…

    ed08b1f
  6. serhiy-storchaka
    added a commit that references this issue on Oct 10, 2026

    [3.15] gh-156444: Fix a negated character set with IGNORECASE and LOC…

    93de9ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-regextype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.