[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#38725: Regexp bug
From: |
Davide Brini |
Subject: |
bug#38725: Regexp bug |
Date: |
Tue, 24 Dec 2019 18:30:14 +0100 |
On Mon, 23 Dec 2019 23:09:28 +0100, Chewbaka Roskov <address@hidden>
wrote:
> akem@akem-HP:~$ echo '112233' | sed 's/2*//' ### DOESN'T WORK
> 112233
You're asking for "zero or more twos". At the beginning of the string (and
between each pair of characters) there is indeed a zero-length match for
your regexp, which sed duly replaces with nothing as you asked. Had you
replaced with something or used the /g switch to the "s" command, you'd
have seen it. For example:
$ echo '112233' | sed 's/2*//g'
1133
$ echo '112233' | sed 's/2*/XXX/'
XXX112233
# Blatant test case
$ echo 'abc' | sed 's/2*/XXX/g'
XXXaXXXbXXXcXXX
> akem@akem-HP:~$ echo '112233' | sed 's/1*//' ### THIS ONE WORK
> 2233
In this case 1* matches at the beginning of the string as before, but it's
allowed to match more than zero characters, so the "11" (the match for 1*)
is replaced with nothing.
> akem@akem-HP:~$ echo 'ee112233' | sed 's/1*//' ### BUT THIS ONE DOES NOT
> ee112233
Same as first case.
--
D.