vercmp with "-" [SOLVED]
Rainer Müller
raimue at macports.org
Sun Dec 18 07:41:19 PST 2011
Hi,
On 2011-12-17 09:20 , Ryan Schmidt wrote:
> I would say base is clearly wrong here. The proposed change is good
> *as described*, but what got implemented doesn't seem to match what
> we wanted.
Of course I did not try to break any existing regex on purpose. ;-)
But Josh is right, the current behavior in trunk base is bad.
> The code that before worked did this:
>
> - if {[regexp $the_re $line matched upver]} {
>
> "matched" is the entire string matched, and "upver" is the first
> parenthesized expression. Any additional parenthesized expressions
> are ignored.
Okay, that's the problem. I did not think of a regex with multiple
groups. Thanks for chasing this one down.
> Ideally the regexp in the port would have been specified not as:
>
> DNSUpdate([0-9]+(\.\w+)+)s.tgz
>
> but as:
>
> DNSUpdate([0-9]+(?:\.\w+)+)s.tgz
>
> That is, using "?:" to indicate that the additional parentheses are
> not to be counted as matches, only as grouping. But I'll bet we have
> a lot of ports doing this, since it didn't matter before.
Before the change we always used the first group of parentheses. So, if
we find out how many parentheses the regex will produce, we can remove
this many items from the returned list in each loop iteration but only
use the first one as the matched version. This would be easier than
algorithmically modifying the regex.
An alternative would be to use the -indices option of regexp which
returns the position of the match in the string. Then the regex could be
applied multiple times using -start to begin matching where the previous
match ended.
Rainer
More information about the macports-dev
mailing list