GNU bug report logs - #56018
sed bug when using extended regular expressions and [] with backslash character class identifiers.

Previous Next

Package: sed;

Reported by: Bob Power <b_power <at> yahoo.com>

Date: Thu, 16 Jun 2022 12:12:01 UTC

Severity: normal

To reply to this bug, email your comments to 56018 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#56018; Package sed. (Thu, 16 Jun 2022 12:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bob Power <b_power <at> yahoo.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Thu, 16 Jun 2022 12:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bob Power <b_power <at> yahoo.com>
To: "bug-sed <at> gnu.org" <bug-sed <at> gnu.org>
Subject: sed bug when using extended regular expressions and [] with
 backslash character class identifiers.
Date: Thu, 16 Jun 2022 10:42:55 +0000 (UTC)
[Message part 1 (text/plain, inline)]
# sed --version
sed (GNU sed) 4.5
Copyright (C) 2018 Free Software Foundation, Inc.

Given
\s = whitespace, [\s] should also be a whitespace.

We should get the same results if we use [\s] in place of \s

but we don't...

test 1: replace all whitespace sequences with xx using \s - OK/Works as expected;

echo 'A  BC  D' | sed -E 's/\s+/xx/g' 
AxxBCxxD

test 2: replace all whitespace sequences with xx using [\s] - fails/not as expected - should be same as test 1 output;

echo 'A  BC  C' | sed -E 's/[\s]+/xx/g'
A  BC  C

After some experimenting it seems that inside [] sed sees all \ as literal \ characters and not part of class identifiers..

echo 'A  B\C  Csstt' | sed -E 's/[\s]+/xx/g'
A  BxxC  Cxxtt

[Message part 2 (text/html, inline)]

This bug report was last modified 2 years and 195 days ago.

Previous Next


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