bug-gawk
[Top][All Lists]
Advanced

[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: arnold
Subject: Re: Does gawk manual mention how an empty regex should be handled?
Date: Wed, 31 Mar 2021 10:34:24 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Arkadiusz Drabczyk <arkadiusz@drabczyk.org> wrote:

> TIL that empty regex matches any string:

Not sure what "TIL" is.

> $ 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.

Thanks,

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]