bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in function match() ?


From: arnold
Subject: Re: Bug in function match() ?
Date: Thu, 21 Sep 2023 14:55:14 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thanks for taking the time to report an issue.

Both Eli and Andy have provided correct solutions for what
you want to do.

Thanks!

Arnold

Canarecci Mauro <mauro.canarecci@telecomitalia.it> wrote:

> Dear Sirs,
> I'm having a weird behavior with the match() function
>
> I'm using GAWK 5.1.0 in Windows 10.
> GAWK was compiled with MinGW
>
> Running the following program (test1.awk)
>
> BEGIN {
>           # convert a date string to ISO format
>            date="12/31/2023"
>            if 
> (match(date,/^(0?[1-9]|1[12])\/(0?[1-9]|[12][0-9]|3[01])\/([1-2][0-9]{3})$/,D)!=0)
>  {
>                         print D[3] "-" D[1] "-" D[2]
>                         }
>                 }
> I get the following output :
> 2023-12-31
>
> as expected
>
> However, when I run (test2.awk)
>
> BEGIN {
>            # convert a date string to ISO format
>
>            
> date_regex=/^(0?[1-9]|1[12])\/(0?[1-9]|[12][0-9]|3[01])\/([1-2][0-9]{3})$/
>            date="12/31/2023"
>            if (match(date, date_regex, D)!=0) {
>                         print D[3] "-" D[2] "-" D[1]
>                         }
>                 }
>
> I get the following output :
> --
>
> That depends on the facts that the matched subexpressions don't get assigned 
> to the array D, although "date" matched "date_regex" as expected.
>
> Although I didn't run the very latest version of gawk, I haven't found any 
> reference to this behaviour before, or a fix issued to solve a problem like 
> this.
> I hope this, if confirmed as a bug, could help improve gawk.
>
> Regards
>
> MAURO CANARECCI
>
>
> Gruppo TIM - Uso Interno - Tutti i diritti riservati.
>
> Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle 
> persone indicate. La diffusione, copia o qualsiasi altra azione derivante 
> dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora 
> abbiate ricevuto questo documento per errore siete cortesemente pregati di 
> darne immediata comunicazione al mittente e di provvedere alla sua 
> distruzione, Grazie. 
>
> This e-mail and any attachments is confidential and may contain privileged 
> information intended for the addressee(s) only. Dissemination, copying, 
> printing or use by anybody else is unauthorised. If you are not the intended 
> recipient, please delete this message and any attachments and advise the 
> sender by return e-mail, Thanks.
>
> Rispetta l'ambiente. Non stampare questa mail se non รจ necessario.



reply via email to

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