[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in function match() ?
From: |
Eli Zaretskii |
Subject: |
Re: Bug in function match() ? |
Date: |
Thu, 21 Sep 2023 21:47:54 +0300 |
> From: Canarecci Mauro <mauro.canarecci@telecomitalia.it>
> Date: Thu, 21 Sep 2023 18:39:20 +0000
>
> 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 :
> --
Try this instead:
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];
}
}