bug-gnulib
[Top][All Lists]
Advanced

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

Re: possible bug in regex and dfa


From: arnold
Subject: Re: possible bug in regex and dfa
Date: Sun, 18 Jul 2021 06:56:14 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Paul Eggert <eggert@cs.ucla.edu> wrote:

> On 7/15/21 1:48 PM, Arnold Robbins wrote:
> > The regexp used there, ".^", to my mind should be treated as invalid.
>
> No, that regular expression is valid because "." matches newline in 
> POSIX EREs. So the "." matches a newline, and the following "^" matches 
> the start of the next line.

Bruno Haible <bruno@clisp.org> wrote:

> > No, that regular expression is valid because "." matches newline in 
> > POSIX EREs.
>
> And if you don't like this, you need to remove the RE_DOT_NEWLINE flag from
> the value that you pass to re_set_syntax.

Dot matching newline isn't the issue here.

It's ^ matching in the middle of a string.  For my purposes, ^ should
only match at the beginning of a *string* (as $ should only match at
the end of a string).  I haven't rechecked POSIX, but this is how awk
has behaved since forever. (And how I've documented things in the manual,
also since forever.)

For RS, gawk treats the concatenation of the input files as one long
string, so ^ should only match at the very beginning, and $ at the
very end.

But even for strings the GNU regex routines seem to get it wrong:

$ cat y.awk
BEGIN {
        data = "a.^b\na.^b\n"
        gsub(/.^/, ">&<", data)
        print data
}

$ mawk -f y.awk         # gets it right IMHO
a.^b
a.^b

$ nawk -f y.awk
nawk: syntax error in regular expression .^ at 
 source line number 3 source file y.awk
 context is
                gsub(/.^/, ">&<", >>>  data) <<< 

$ ./gawk -f y.awk
a.^b>
<a.^b>
<

Is there some way I can get the regex routines (and dfa) to relate
to ^ and $ as relative to the *string* and not the *line*?

Thanks,

Arnold



reply via email to

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