[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [TSVN] regex help

From: Toby Johnson <toby_at_etjohnson.us>
Date: 2005-02-17 20:26:15 CET

SteveKing wrote:

> Hi guys,
>
> Seems I haven't mastered the regexes yet. I'm trying to improve the
> issuetracker specs to use only one regex instead of two, but my test
> doesn't work.
>
> The test log message:
> this is a test logmessage: issue 2222\nIssue #456, 678, #901, #100 #456
> and the regex string which _should_ match only the issue numbers 2222,
> 456, 678, 901, 100:
> [Ii]ssue #?([0-9]+)(?:(?:, #?([0-9]+))+)?
>
> But it only returns 2222, 456, 100 in the groups - it leaves out 678
> and 901! Can you please help me out here and explain why this happens?

The second half of the text to match is returning only two values
because you have two grouping parentheses which return values. It's not
returning a particular match twice, it's returning two matches once, if
that makes sense.

The problem here is that a plus sign is greedy -- it will gobble up
everything it can until there are no more matches. The alternative is +?
which matches as little as possible. There's no between-ground to say
"match this as many times as possible". And using a GLOBAL replace won't
work, because it would keep matching the same issue number instead of
each one consecutively.

In short, I can't think of any way to accomplish what you're trying to
do without using two passes:
Pass 1 (NOCASE): ((?:issue)[\d\s#,]+)
Pass 2 (fed the results from pass 1): (\d+)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Thu Feb 17 20:27:53 2005

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.