Skip to content
Discussion options

You must be logged in to vote

Yes. Your issue is assuming that Python's len function on a str will report a length consistent with the length used by ripgrep. Indeed, ripgrep uses byte offsets exclusively. Python, by contrast, uses codepoint offsets. Using codepoint offsets in ripgrep would be wildly inappropriate for two reasons. First is that you would need to decode the data into a sequence of codepoints before you could use the offsets to slice into it. By using byte offsets, you can store the data as a sequence of bytes in contiguous memory, and use the offsets to index or slice into it directly. Second is that ripgrep isn't limited to searching UTF-8. It can search anything, including invalid UTF-8. Codepoint of…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3240 on December 09, 2025 13:06.