google / google/re2

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

Open
#595 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
9.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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".
```python
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.