Skip to content

grep: allow ERE repeat operators after ^ and $ anchors - #251

Open
yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-ere-repeat-after-anchor
Open

yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-ere-repeat-after-anchor

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

In extended mode (-E), GNU grep accepts a repetition operator immediately following ^ or $:

  • After ^ (e.g. ^*q, (^+q)), it warns <op> at start of expression and searches as ^.
  • After $ (e.g. q, jo$+), it accepts it silently ($ when min >= 1, or ($|) when zero repetitions are allowed).

This normalizes unescaped, out-of-bracket anchor-followed repeat operators in RegexMode::Extended before Oniguruma compilation.

Fixes #206

Investigated and verified locally with cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test.

Warn and strip repeat operators following `^` (matching GNU grep's `<op> at start of expression`), and accept repeat operators following `$` silently (keeping `$` for positive minimums and `($|)` when zero repetitions are allowed).

Fixes uutils#206
@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-ere-repeat-after-anchor (67aa446) with main (b2fd25a)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.29730% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.20%. Comparing base (b2fd25a) to head (67aa446).

Files with missing lines Patch % Lines
src/matcher.rs 97.29% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #251   +/-   ##
=======================================
  Coverage   97.19%   97.20%           
=======================================
  Files           6        6           
  Lines        2248     2322   +74     
  Branches      243      256   +13     
=======================================
+ Hits         2185     2257   +72     
- Misses         63       65    +2     
Flag Coverage Δ
macOS_latest 98.08% <97.29%> (-0.03%) ⬇️
ubuntu_latest 98.08% <97.29%> (-0.03%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

grep - -E rejects a repeat operator right after ^ or $ (^*, $*, ^+x)

1 participant