Skip to content

grep - the interval {,} (\{,\} in BRE) is rejected or read literally; GNU reads it as {0,} #203

Open

Description

@sylvestre

Known: closed PR #152 (closed by its author without merging) — #152

GNU grep reads an interval with neither bound, {,}, as {0,} (the same as *). In basic
mode uu_grep rejects \{,\} with an Oniguruma error and exit 2; in extended mode it reads
{,} as literal text and so selects different lines. PR #152 rewrote the pattern text and
was closed; no issue tracks the behaviour.

Exposed by the GNU test bre (Spencer BRE test #40, a\{,\} must match a\{,\}).

Reproduction

Rust (incorrect)

$ printf 'mo\nmooo\n' | ./target/release/grep 'mo\{,\}'
grep: invalid pattern "mo\{,\}": invalid repeat range {lower,upper}
# Exit code: 2

$ printf 'mo\nmooo\n' | ./target/release/grep -E 'mo{,}'
# Output: (none)
# Exit code: 1

GNU (correct)

$ printf 'mo\nmooo\n' | LC_ALL=C /usr/bin/grep 'mo\{,\}'
mo
mooo
# Exit code: 0

$ printf 'mo\nmooo\n' | LC_ALL=C /usr/bin/grep -E 'mo{,}'
mo
mooo
# Exit code: 0

Test

#[test]
fn empty_interval_means_zero_or_more() {
    for args in [&["-c", "bz\\{,\\}"][..], &["-c", "-E", "bz{,}"][..]] {
        let (_s, mut c) = ucmd();
        c.args(args)
            .pipe_in("b\nbzzz\nq\n")
            .succeeds()
            .stdout_only("2\n");
    }
}

Exposed by the GNU grep test suite: bre.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions