Skip to content

Search &[u8] haystacks in regex_lite #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

01mf02
Copy link
Contributor

@01mf02 01mf02 commented Jul 31, 2025

To quote the regex_lite docs:

Currently, this crate only supports searching &str. It does not have APIs for searching &[u8] haystacks, although it is planned to add these in the future if there’s demand.

This PR adds such an API in form of regex_lite::bytes::Regex, mirroring regex::bytes::Regex.
Thanks, @BurntSushi, for leaving some breadcrumbs in the source code that made this easier, in particular your hint in interpolate::bytes. This is much appreciated, as well as all your effort that went not only in the careful and beautiful API design, but also your very detailed and user-friendly documentation. Thanks a lot for your awesome work.

I made this PR because I need this functionality as part of jaq, where I want to transition from String to (a variation of) Vec<u8>, inspired by your "UTF-8 by convention" idea.
I did not cargo fmt this PR in order to make reviewing as easy as possible.

(Note to self: If I ever have to convert a lot of b"foo" to &b"foo"[..] again, this is how to do it in vim for all matches on the current line: :s/b"\([^"]*\)"/\&b"\1"[..]/g.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant