Skip to content

regex zero-width match starts inside a UTF-8 character #5606

Closed

Description

@robertmorelli

issue:
(?!é)(?!$) cannot match at any character boundary in "éé": before either é, (?!é) fails, and at the end, (?!$) fails. Racket instead reports a match at byte offset 1, inside the first é.

repro:

(regexp-match-positions
 #px"(?!é)(?!$)"
 (open-input-bytes #"\303\251\303\251"))
; '((1 . 1)) (should be #f)

expected:
The result should be #f. There is no character boundary where both assertions succeed.

system:
Racket v9.3 [cs]
macOS 27.0 (build 26A428), arm64

Activity

  1. mflatt commented on Oct 12, 2026

    @mflatt
    Member

    The problem here is that matching is always at the byte level internally, and a search for a non-anchored match (i.e., one that doesn't have to start at the beginning of the input) tries byte offsets instead of character offsets of the UTF-8-encoded input.

    When given a string input, clearly the search for a match should change to consider offsets that correspond to UTF-8 encodings. For consistency, it should also behave that way when given an input port or byte string to match. I think that change won't affect existing uses of string regexps that are applied to streams that have a mixture of binary data and text, because bad encodings are handled in a way that means a bad encoding will not consume the beginning of a valid encoding.

    Edit: "Won't affect" isn't right, because the point would be to change things. I mean that it seems unlikely to affect an existing use of regexps that is working as intended, but I'm not completely certain.

  2. added a commit that references this issue on Oct 14, 2026
    3ffd82f
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions