# 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