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

Full log


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 3 years and 1 day ago.

Previous Next


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