Skip to content

Add support for lookarounds in regex filtering (fancy-regex integration) #905

@sabbellasri

Description

@sabbellasri

Background

The recently added regex filtering feature works well using Rust's regex crate. However, it does not support advanced regex features like lookarounds ((?=...), (?!...), etc.), which can be useful for more complex filtering scenarios.

This limitation was observed during usage and also discussed in #554.

Problem

Rust's regex crate intentionally does not support lookarounds due to performance guarantees (linear-time matching using NFA).

As a result, users cannot write certain expressive patterns that are commonly used in tools like grep.

Proposed Solution

Integrate fancy-regex as an optional or fallback engine:

  • Use regex crate for standard/simple patterns (fast path)
  • Fallback to fancy-regex when advanced features (like lookarounds) are detected

This approach aligns with how fancy-regex works internally — delegating simple cases to the fast NFA engine and handling complex patterns separately.

Benefits

  • Enables support for lookarounds and other advanced regex features
  • Maintains performance for common/simple patterns
  • Improves usability for users familiar with grep-style filtering

Considerations

  • Performance impact for complex patterns
  • Need for pattern detection logic (to decide which engine to use)
  • Additional dependency (fancy-regex)

Next Steps

I will start implementing this and open a PR shortly.

cc: @beelze

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions