[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Does gawk manual mention how an empty regex should be handled?
From: |
Arkadiusz Drabczyk |
Subject: |
Re: Does gawk manual mention how an empty regex should be handled? |
Date: |
Wed, 31 Mar 2021 18:58:30 +0200 |
On Wed, Mar 31, 2021 at 10:34:24AM -0600, arnold@skeeve.com wrote:
> Hi.
>
> Arkadiusz Drabczyk <arkadiusz@drabczyk.org> wrote:
>
> > TIL that empty regex matches any string:
>
> Not sure what "TIL" is.
It means Today I Learned (sorry, I thought it's commonly known)
> > $ awk 'BEGIN { print "abc" ~ "" }'
> > 1
> > $ awk 'BEGIN { print "abc" ~ // }'
> > 1
> >
> > It can also be reproduced with mawk, Busybox awk and FreeBSD
> > awk. However, I wasn't able to find an explanation of that behavior in
> > the gawk manual.
>
> The match is to the empty string before and after each character.
> You can see this with gsub():
>
> $ gawk 'BEGIN { x = "ABC"
> > gsub(//, "x", x) ; print x }'
> xAxBxCx
>
> > Is it actually documented somewhere?
>
> I thought it was, but it may not be. I can't find it at the moment,
> but I will take a harder look later.
ok, thank you.
--
Arkadiusz Drabczyk <arkadiusz@drabczyk.org>