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: Wolfgang Laun
Subject: Re: Does gawk manual mention how an empty regex should be handled?
Date: Wed, 31 Mar 2021 19:48:32 +0200

On Wed, 31 Mar 2021 at 19:04, Arkadiusz Drabczyk <arkadiusz@drabczyk.org>
wrote:

> ... but someone here
>
> https://boost-users.boost.narkive.com/PA1Fxdws/regex-empty-regular-expression
> said:
>
> "An empty regex has always been an error in Boost.Regex (because I
> couldn't think of a legitimate use for it)."
>

And then the author recommends /(?:)/ as a work-around which makes his
argument rather wobbly: if // is an error, why not /(?:)/?

I disagree very much with the author because I have written much code to
generate code. Handling the "zero case" is always a nuisance unless you can
generate it along with one or more.

The following may not be required very frequently, or you may work around
the non-availability of // in some other way, but isn't it *convenient *to
be able to write
     $str = "><";   # Perl 5
     if( $str =~ />(a|b|c|)</ ){  ## not />(a|b|c)?</ which makes $1
undefined
         print "found '$1'\n";
     }

(Aside: I would use /.{0,0}/ as a work-around in Boost, just because it
looks so eye-catching ;-) )

Wolfgang




-- 
Wolfgang Laun


reply via email to

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