bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] How to extract the matches with {n,m} in regex?


From: arnold
Subject: Re: [bug-gawk] How to extract the matches with {n,m} in regex?
Date: Sat, 15 Dec 2018 12:53:40 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Peng Yu <address@hidden> wrote:

> Hi,
>
> I only see "B" is returned but not "A". Is it possible to return it? Thanks.
>
> $ awk -e 'BEGIN { s=" A B"; match(s, /( +([A-Z]+)){1,2}$/, a); for(k
> in a) print k, a[k]; }'
> 0start 1
> 0length 4
> 1start 3
> 2start 4
> 2length 1
> 1length 2
> 0  A B
> 1  B
> 2 B

I don't see a bug here.  The full text of 's' matched, as shown by the
values for 0,start and 0,length.  The first parenthesized expression is
space followed by a letter anchored to the end of the string, by the $
sign; you see that in the `1  B'; the first space is from the print,
the second is the space before B.  The second parenthesized expression
is the letter at the end of the string.

The values here are those returned directly by the underlying C regex
engine from GNULIB.

Arnold



reply via email to

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