Skip to content

\?, \+, \|, \{m\}, \{m,\} and \{m,n\} in BRE #288

Closed

Description

@e-kwsm

revision: 3504109

From POSIX BRE:

The '?', '+', and '|' characters; it is implementation-defined whether "?", "+", and "|" each match the literal character '?', '+', or '|', respectively, or behave as described for the ERE special characters '?', '+', and '|', respectively (see 9.4.3 ERE Special Characters).

Note:
A future version of this standard may require "\?", "\+", and "\|" to behave as described for the ERE special characters '?', '+', and '|', respectively.

GNU and BSD sed’s treat \?, \+, and \| in BRE as the ERE counterparts, whereas uutils does not:

$ cargo run --quiet -- -n -e '/cats\?$/p' <<< $'cat\ncats?'
cats?
$ sed -n -e '/cats\?$/p' <<< $'cat\ncats?'
cat
$ cargo run --quiet -- -n -e '/se\+d/p' <<< $'seed\nse+d'
se+d
$ sed -n -e '/se\+d/p' <<< $'seed\nse+d'
seed
$ cargo run --quiet -- -n -e '/foo\|bar/p' <<< $'foo\nfoo|bar'
foo|bar
$ sed -n -e '/foo\|bar/p' <<< $'foo\nfoo|bar'
foo
foo|bar

POSIX does not mandate the behavior, but it would be preferable.

Activity

  1. e-kwsm commented on Feb 5, 2026

    @e-kwsm
    ContributorAuthor

    When a BRE matching a single character, a subexpression, or a back-reference is followed by an interval expression of the format "\{m\}", "\{m,\}", or "\{m,n\}", together with that interval expression it shall match what repeated consecutive occurrences of the BRE would match. The values of m and n are decimal integers in the range 0<=m<=n<={RE_DUP_MAX}, where m specifies the exact or minimum number of occurrences and n specifies the maximum number of occurrences. The expression "\{m\}" shall match exactly m occurrences of the preceding BRE, "\{m,\}" shall match at least m occurrences, and "\{m,n\}" shall match any number of occurrences between m and n, inclusive.

    The brace quantifiers are mandatory but currently uutils does not support them.

  2. changed the title [-]`\?`, `\+`, and `\|` in BRE[/-] [+]`\?`, `\+`, `\|`, `\{m\}`, `\{m,\}` and `\{m,n\}` in BRE[/+] on Feb 5, 2026
  3. LoukasPap commented on Feb 16, 2026

    @LoukasPap
    Contributor

    I'll check that out too.

  4. LoukasPap commented on Apr 2, 2026

    @LoukasPap
    Contributor

    Waiting to work on top of #328 when it gets merged.

  5. e-kwsm commented on May 1, 2026

    @e-kwsm
    ContributorAuthor

    Thank you, but BRE brace quantifiers are not supported yet (60243b4).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions