Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ impl CompiledPattern {
// GNU grep supports `{,n}` as an alias for `{0,n}`.
syntax.enable_behavior(SyntaxBehavior::SYNTAX_BEHAVIOR_ALLOW_INTERVAL_LOW_ABBREV);
}
if matches!(config.regex_mode, RegexMode::Basic | RegexMode::Extended) {
// GNU grep supports \` and \' as buffer anchors in BRE and ERE.
syntax.enable_operators(SyntaxOperator::SYNTAX_OPERATOR_ESC_GNU_BUF_ANCHOR);
}
if config.regex_mode == RegexMode::Perl {
// GNU grep supports `(?P<name>...)`.
// Unfortunately, the onig crate defines the OP2 flag without the
Expand Down
15 changes: 15 additions & 0 deletions tests/test_grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ fn bre_gnu_extensions() {
.stdout_only("*foo\n**foo\n");
}

#[test]
fn gnu_buffer_anchors() {
let (_s, mut c) = ucmd();
c.args(&[r"\`c\|r\'"])
.pipe_in("cat\nscat\ntar\ndog\n")
.succeeds()
.stdout_only("cat\ntar\n");

let (_s, mut c) = ucmd();
c.args(&["-E", r"\`c|r\'"])
.pipe_in("cat\nscat\ntar\ndog\n")
.succeeds()
.stdout_only("cat\ntar\n");
}
Comment on lines +88 to +101
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be expressed in just two tests, no?

Copy link
Copy Markdown
Contributor Author

@wondr-wclabs wondr-wclabs Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I collapsed this to two command invocations: one BRE case and one ERE case. Each pattern now covers both GNU buffer anchors in one command:

BRE: \`c\|r\'
ERE: \`c|r\'

That keeps the mode distinction explicit while avoiding four near-identical command setups. Focused validation after the change: cargo test --test test_grep gnu_buffer_anchors.


#[test]
fn ere_metacharacters() {
let cases: &[(&[&str], &str, &str)] = &[
Expand Down
Loading