This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
To: =?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=
From: Kevin Maples <kmaples@collab.net>
Subject: Re: OT : Regexp tips
Date: Tue, 22 Oct 2002 14:09:09 -0700
Heya,
An answer is below; don't peek if you don't need to.
The simple answer to the problems you were having with the regex is your
use of parens for both grouping and capture (see the diagram below), and
your use of 'zero or more' (*) in cases that you likely meant 'one or
more' (+), particularly in the case of whitespace (which seems to be
your delimiter). The match that you're working with is slightly
complicated by the fact that the beginning and ending of the user's name
isn't distinguished from whitespace inside the name, and in cases like
that, I find it easier to say 'anything which is not something'
(e.g., [^\]]) than trying to catch all the possibilities.
Keep in mind that perl captures matches in parens counting opening
parens left-to-right (not when parens close); this may have given you an
off-by-one error in your count. If you were trying to say that the
entire clause past yes/no is optional, you could try starting person at
4 (instead of 3).
Hope that helps,
- Kevin
<spoiler>
my @strings = (
'Animation 1 Jean-Yves Audouard [Shok] [xsi] wip',
'Annotation 0 Kevin Maples [regex] [perl] blap',
);
foreach( @strings ){
# compare to:
# m/^(\w*)\s*(\w)(\s*([\w\s]*)\[([\w\s]*)\]\s\[([\w\s]*)\]\s(.*)|)$/;
# ^---^ ^--^^-----------------------------------------------^
(1,2,3)
# ^-------^ ^-------^ ^-------^ ^--^
(4,5,6,7)
#
m/^(\w+)\s+(\d+)\s+([^\]]+)\s+\[([^\]]+)\]\s+\[([^\]]+)\]\s+(\w+)/;
my ($taskname, $yesno, $person, $component, $software, $status) =
($1, $2, $3, $4, $5, $6);
print "----------------------------\n";
print "task: $taskname\n";
print "yes: $yesno\n";
print "person: $person\n";
print "comp: $component\n";
print "soft: $software\n";
print "status: $status\n";
}
</spoiler>
On Tuesday, October 22, 2002, at 01:34 PM, Jean-S