GNU bug report logs - #70476
`**` GNU extension only works when ERE syntax is enabled

Previous Next

Package: sed;

Reported by: Dylan Brotherston <d.brotherston <at> unsw.edu.au>

Date: Fri, 19 Apr 2024 23:06:11 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Dylan Brotherston <d.brotherston <at> unsw.edu.au>
To: 70476 <at> debbugs.gnu.org
Cc: "dylanbbbrother <at> gmail.com" <dylanbbbrother <at> gmail.com>
Subject: bug#70476: `**` GNU extension only works when ERE syntax is enabled
Date: Fri, 19 Apr 2024 17:44:03 +0000
[Message part 1 (text/plain, inline)]
$ sed --version
sed (GNU sed) 4.9

The documentation for sed BRE syntax states:
> As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*
https://www.gnu.org/software/sed/manual/sed.html#BRE-syntax
But sed reports an error when ** is used in a BRE expression

$ seq 10 20 | sed 's/1**//'
sed: -e expression #1, char 7: Invalid preceding regular expression

and only allows this syntax when ERE syntax is enabled

$ seq 10 20 | sed -E 's/1**//'
0

2
3
4
5
6
7
8
9
20

grep, which also implements this GNU extension, allows ** in BRE syntax

$ seq 10 20 | grep -o '1**'
1
11
1
1
1
1
1
1
1
1
$ seq 10 20 | grep -oE '1**'
1
11
1
1
1
1
1
1
1
1

Additionally, the documentation for the `--posix` flag states
> disable all GNU extensions.
** is specifically documented as a GNU extension, but `--posix` doesn't disable the use of **

$ seq 10 20 | sed --posix -E 's/1**//'
0

2
3
4
5
6
7
8
9
20
[Message part 2 (text/html, inline)]

This bug report was last modified 1 year and 56 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.