Skip to content

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

@e-kwsm

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.

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