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 — Negative lookbehind ignored under `re.IGNORECASE | re.LOCALE` · Issue #155985 · python/cpython

Negative lookbehind ignored under re.IGNORECASE | re.LOCALE #155985

New issue
Copy link
New issue
Copy link
Closed
#156445
Closed
Negative lookbehind ignored under re.IGNORECASE | re.LOCALE#155985
#156445
Copy link
Labels
3.15bugs and security fixesbugs 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

@fedonman
fedonman
opened on Aug 18, 2026
Issue body actions

Bug description:

On the main branch a negative lookbehind after a character class is ignored for bytes patterns when both re.IGNORECASE and re.LOCALE are set. [b] matches b'B' under those flags, so \w(?<!b) must not match b'B', but it does. The same flag pair also lets the new [A--B] difference operator match characters that are in B.

import re

W = re.IGNORECASE | re.LOCALE
print(re.fullmatch(rb'[b]', b'B', W))
print(re.fullmatch(rb'\w(?<!b)', b'B', W))

Output on main:

<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.14.4 prints.

_fuse_difference() in Lib/re/_optimizer.py rewrites <charset> (?<![B]) into a single character set carrying NEGATE without seeing the compile flags, and under this flag pair that set compiles to IN_LOC_IGNORE, which tests the whole set once per locale case.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-155985: Do not fuse a set difference under IGNORECASE with LOCALE #155993

Activity

  1. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-regex
    3.15bugs and security fixesbugs and security fixes
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Aug 18, 2026
  2. serhiy-storchaka commented on Aug 27, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 27, 2026
    Member
    More actions

    There is a deeper old bug in the engine (#156444). Fixing it also fixes this issue.

  3. serhiy-storchaka
    closed this as completedin #156445on Aug 27, 2026
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.15bugs and security fixesbugs 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 01402520 — 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.