Skip to content

Feature request: supporting lookarounds (PCRE2 or fancy-regex) #49

@LeoniePhiline

Description

@LeoniePhiline

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.

Among other things, this makes it possible to use look-around and backreferences in your patterns, which are not supported in ripgrep's default regex engine. PCRE2 support can be enabled with -P/--pcre2 (use PCRE2 always) or --auto-hybrid-regex (use PCRE2 only if needed). An alternative syntax is provided via the --engine (default|pcre2|auto-hybrid) option.

Pivot from rust-pcre2 to fancy-regex

See #49 (comment). grep::pcre2 is unlikely to expose pcre2_substitute any time soon, due to obvious maintenance overload.

The fancy-regex crate is the go-to escape from rust's regex 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.md

However, since fastmod already uses grep (rg as a library), it might just as well enable the pcre2 cargo dependency flag and use grep::pcre2 just as ripgrep does: https://github.com/BurntSushi/ripgrep/blob/327d74f1616e135a6eb09a0c3016f8f45cfc0cfc/crates/core/search.rs#L199

Enum-dispatched regex matcher and replacer based on regex and fancy-regex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions