bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: match does not work with minus sign


From: Seb
Subject: Re: match does not work with minus sign
Date: Wed, 10 Dec 2008 08:58:48 +0100

Le Tue, 09 Dec 2008 19:47:54 -0500
Paul Romanyszyn <address@hidden> a écrit:

Hello,

> With Ubuntu 7.10 32 bit I found this problem when parsing git-diff 
> output. I compiled the latest stable version and it also had the 
> problem. One plus matches one two or three  but one minus only matches 
> one minus.
> Test program
> BEGIN {
>     data1 = "+"
>     data2 = "++"
>     data3 = "+++"
>     printf("%d %d 
> %d\n",match(data1,data1),match(data1,data2),match(data1,data3))
>     data1 = "-"
>     data2 = "--"
>     data3 = "---"
>     printf("%d %d 
> %d\n",match(data1,data1),match(data1,data2),match(data1,data3))
> }
> 
> Output
> address@hidden:~/gawksrc$ gawk-3.1.6/gawk -f testmatch.awk
> 1 1 1
> 1 0 0

The syntax of match() is "match(<target>,<pattern>)". So, here it's true that
you can't match two or three minus in one. :)

The comparison with plus drawn you to see a problem, because "+" is syntaxically
significant in a pattern (it means "one or more"). Replace "+" with "\\+" in 
your
patterns to get things obviously consistent.

++
Seb.




reply via email to

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