-
Notifications
You must be signed in to change notification settings - Fork 43
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
Feature request: supporting lookarounds (PCRE2 or fancy-regex) #49
Comments
Update: The Looking at BurntSushi/rust-pcre2#26 and BurntSushi/rust-pcre2#27 for the implementation of PCRE2 support, this looks like a dead end. Andrew appears to not have the bandwidth for maintenance, as even quality PRs from years ago are unreviewed. I will drop the attempts to implement PCRE2 support and pivot to It supports lookarounds, with the same risk for catastrophic backtracking, which is not relevant to |
Another update: Andrew Gallant expressed openness towards accepting a PR to the pcre2 crate to expose substitution. BurntSushi/ripgrep#2763 (reply in thread) I am interested in trying to create a quality patch and get it merged. If that succeeds, then fastmod could get its PCRE2 mode after all. The stale PRs in https://github.com/BurntSushi/rust-pcre2 do not give me much hope for a fast solution, but there are lots of reasons for hope of resolving this entanglement: Fish shell appears to have more bandwidth (or more need) to maintain a PCRE2 substitution patch in their fork, which is already implemented. Their fork remains maintained, since UTF-32 matching was not upstreamed after all. This means, we have a quite fragmented situation:
All this sounds quite doable for a private project, but getting the changes merged back into https://github.com/facebookincubator/ sounds ... somewhat unlikely? ➡️ Ideally, the substitution feature (which BurntSushi has indicated might well be accepted into his upstream A possible route to success:
|
Feature request
First of all, thank you very much for opensourcing
fastmod
! I find it quite joyful to use!At the moment, it does not have support for positive and negative lookaheads and lookbehinds.
These can be very much required with complex searches.
Security
Note that
fastmod
is usually run over trusted code, not over untrusted user input, thus an opt-in--pcre2
--fancy
flag should not pose any unacceptable security risk.Prior art
Note that
ripgrep
(which does search, but not replace) has optional support for switching its regex engine to use PCRE2.Pivot from
rust-pcre2
tofancy-regex
See #49 (comment).
grep::pcre2
is unlikely to exposepcre2_substitute
any time soon, due to obvious maintenance overload.The
fancy-regex
crate is the go-to escape from rust'sregex
crate where-ever lookarounds are uncircumventable.Implementation
https://docs.rs/pcre2/ should be usable as a base for this feature.This crate is recommended by and instead of https://github.com/BurntSushi/ripgrep/blob/master/crates/pcre2/README.mdHowever, sincefastmod
already usesgrep
(rg
as a library), it might just as well enable thepcre2
cargo dependency flag and usegrep::pcre2
just asripgrep
does: https://github.com/BurntSushi/ripgrep/blob/327d74f1616e135a6eb09a0c3016f8f45cfc0cfc/crates/core/search.rs#L199Enum-dispatched regex matcher and replacer based on
regex
andfancy-regex
.The text was updated successfully, but these errors were encountered: