Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Multiple Captures under one group

Reply
Thread Tools

Multiple Captures under one group

 
 
amyl@paxemail.com
Guest
Posts: n/a
 
      06-29-2005
I am having a hard time working out a regular expression that can
capture multiple entries under a group.

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

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.

Here is the expression that I have up to that point.
(?<Date>(\d\d/\d\d/\d+ \d\d:\d\d:\d\d)) (?<GROUPID>(G\w+)) Results
group \[groups=(?<groupsnum>([\-\d]*))\]

Is what I am asking possible?
Thanks
Amy.

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      06-29-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am having a hard time working out a regular expression that can
> capture multiple entries under a group.
>
> 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
>
> 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.
>
> Here is the expression that I have up to that point.

[complex RE snipped]

You know, it always amazes me to what length people go to come up with the
most intriguing REs for a problem that could be solved much easier with two
or three lines of very straight-forward, simple code. Why not just

use warnings; use strict;
my$text = '04/15/2005 00:01:37 G3C8F49 Results group [groups=7]: Sloan=SET
Jones=OK JBUILD1=FAIL';
my @res=(split(/ /, $text))[-3..-1];
for (@res) {s/=.*$//;}
print "@res";

jue


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-29-2005
(E-Mail Removed) wrote:
> I am having a hard time working out a regular expression that can
> capture multiple entries under a group.
>
> 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
>
> My goal is to have a "group" called groupnames that captures "Sloan,
> Jones, JBUILD1".


my @groupnames;
push @groupnames, $1 while /(\w+)=\w+(?:\s+|$)/g;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-29-2005
(E-Mail Removed) <(E-Mail Removed)> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Fabian Pilkowski
Guest
Posts: n/a
 
      06-30-2005
* Tad McClellan schrieb:
> (E-Mail Removed) <(E-Mail Removed)> wrote:
>
>> 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;


Seems there is always a space in front of the names. We could simply
catch all strings between " " and "=".

my @groupnames = / (\w+)=/g;

regards,
fabian
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Match a pattern multiple times, returning matches, captures andoffset? Markus Fischer Ruby 9 04-08-2011 07:53 PM
MatchData captures... expected two items, but got one? Sarah Allen Ruby 7 03-02-2010 06:11 PM
Screen captures Joshua Beall HTML 4 01-19-2004 06:10 PM
Re: Movie File screen captures to .jpg or .gif? °Mike° Computer Support 0 06-28-2003 01:13 PM
Re: Movie File screen captures to .jpg or .gif? Mitch Computer Support 0 06-28-2003 12:53 PM



Advertisments