Skip to content

When using the re2 Python bindings, replacing the anchor "$" with re2.subn inserts the replacement twice #595

@benediktschlager

Description

@benediktschlager

I observed that when using the re2 Python bindings, $ replaces the end of the string twice.

What is the current behavior?

This test case fails with the result being "Hello WorldEOSEOS".

import re2

def test_re2_dollar_sign():
    end_of_string = re2.compile("$")
    (result, matches) = end_of_string.subn("EOS", "Hello World")

    assert result == "Hello WorldEOS"
    assert matches == 1

What is the desired behavior?

The result should be "Hello WorldEOS".

I'm using google-re2 in version 1.1.20251105 and Python version 3.11.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions