Skip to content
Closed
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
6 changes: 6 additions & 0 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ impl CompiledPattern {
// 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::Basic {
// GNU grep accepts \s and \S as whitespace shorthands in BRE.
// Follow Oniguruma's operator directly here; remaining invalid
// UTF-8 differences are engine semantics, not local syntax gaps.
syntax.enable_operators(SyntaxOperator::SYNTAX_OPERATOR_ESC_S_WHITE_SPACE);
}
if config.regex_mode == RegexMode::Perl {
// GNU grep supports `(?P<name>...)`.
// Unfortunately, the onig crate defines the OP2 flag without the
Expand Down
21 changes: 21 additions & 0 deletions tests/test_grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ fn gnu_buffer_anchors() {
.stdout_only("cat\ntar\n");
}

#[test]
fn bre_whitespace_shorthands() {
let (_s, mut c) = ucmd();
c.args(&[r"\s"])
.pipe_in("a b\nxy\n")
.succeeds()
.stdout_only("a b\n");

let (_s, mut c) = ucmd();
c.args(&["-c", r"\S"])
.pipe_in("aS b\n \nx\n")
.succeeds()
.stdout_only("2\n");

let (_s, mut c) = ucmd();
c.args(&[r"\s\+"])
.pipe_in("a b\nxy\n")
.succeeds()
.stdout_only("a b\n");
}

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