Skip to content

Disagreement with CPython about which unicode characters are alnum #7518

Closed

Description

@DRMacIver

Summary

The regex module interprets \w as matching more characters than it seems like it should (certainly more than CPython does).

Expected

import re

assert not re.match(r"\w", "\u0345"), r"\w should not match U+0345 (category Mn)"

This assertion should pass, but instead it fails.

Python Documentation

https://docs.python.org/3/library/re.html

This says that it should match anything for which isalnum() is true. This turns out to be also an area where RustPython and CPython disagree. "\u0345".isalnum() returns False on CPython and True on RustPython.

Activity

  1. joshuamegnauth54 commented on Apr 14, 2026

    @joshuamegnauth54
    Contributor

    I took a look into this issue. It turns out that Rust and Python disagree on alphanumeric characters. Rust strictly(?) uses the Unicode property for alphanumeric whereas Python considers visibility. So, \u{0345} is supposed to be combined with another character in order to be visible and therefore isn't considered alphanumeric by Python. Interestingly, Rust actually prints it whereas Python does not.

    println!("\u{0345}");
    print("\u0345")

    ^These differ!

    Full disclosure, I'm not entirely sure if my research and tests are correct. This is just what I found so far. Seems like I'm on the right track, though. 😁 I'll try to fix this issue soon!

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

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions