[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: |
Neil R. Ormos |
Subject: |
Re: Does gawk manual mention how an empty regex should be handled? |
Date: |
Wed, 31 Mar 2021 11:51:30 -0500 (CDT) |
Arkadiusz Drabczyk wrote:
> TIL that empty regex matches any string:
>
> $ 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. Is it actually documented somewhere?
Arguably, yes. Though perhaps it might be generalized or elaborated for
clarity.
| Section 3: Regular Expressions
|
| [...] A regular expression enclosed in slashes ('/') is
| an awk pattern that matches every input record whose text
| belongs to that set. [...]
|
| Section 7.1.6 The Empty Pattern
|
| [...] An empty (i.e., nonexistent) pattern is considered to
| match every input record. [...]