Re: Multiple Captures under one group



amyl@xxxxxxxxxxxx <amyl@xxxxxxxxxxxx> wrote:

> I am having a hard time working out a regular expression that can
> capture multiple entries under a group.


m//g in list context should do the trick nicely.


> Here is the text I am working with
> 04/15/2005 00:01:37 G3C8F49 Results group [groups=7]: Sloan=SET
> Jones=OK JBUILD1=FAIL


Is that really the text you are working with, or did your "helpful"
news posting host word-wrap it for you, thereby breaking it?

The devil is in the details with pattern matching, we absolutely *must*
have the correct string to match.

Such problems can be avoided if you speak Perl rather than English,
as I've done in the code below.

Have you seen the Posting Guidelines that are posted here frequently?


> My goal is to have a "group" called groupnames that captures "Sloan,
> Jones, JBUILD1". I have worked the regular expression I have into
> being able to grab "Sloan", but I can't seem to figure out how to
> capture Jones and JBUILD1 as well.


-----------------------
#!/usr/bin/perl
use warnings;
use strict;

$_ = '04/15/2005 00:01:37 G3C8F49 Results group [groups=7]: Sloan=SET '
. 'Jones=OK JBUILD1=FAIL';

my @groupnames = grep $_ ne 'groups', /(\w+)=/g;

print "'$_'\n" for @groupnames;
-----------------------


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.