in reply to Matching and making accesible an arbitrary number of subpatterns w/a regex?

Splitting on the colon might be your best bet if the nature of your data is field-delimited, but you should also be able to achieve the same with:

my $src_string = 'aaa:bbb:ccc:ddd:eee:'; my @results = $src_string =~ /([^:]*):/g;

Hope this helps,
-v.

"Perl. There is no substitute."
  • Comment on Re: Matching and making accesible an arbitrary number of subpatterns w/a regex?
  • Download Code

Replies are listed 'Best First'.
Re^2: Matching and making accesible an arbitrary number of subpatterns w/a regex?
by Hue-Bond (Priest) on Aug 03, 2006 at 17:36 UTC

    That does not work when the string doesn't contain any colon:

    my $src_string = 'aaa'; my @results = $src_string =~ /([^:]*):/g; use Data::Dumper; print Dumper \@results; __END__ $VAR1 = [];

    --
    David Serrano

      It seems to me from the OP's description that it will always end in a semi-colon. If not, add it:
      my $src_string = 'aaa:bbb:ccc:ddd:eee'; my @results = "$src_string:" =~ /([^:]*):/g;
Re^2: Matching and making accesible an arbitrary number of subpatterns w/a regex?
by ikegami (Patriarch) on Aug 03, 2006 at 17:34 UTC
    Splitting on the colon, you say?
    my $src_string = 'aaa:bbb:ccc:ddd:eee:'; my @results = split /:/, $src_string; pop @results;

    Update: Oops, I missed the last line of the OP. Well, neither solution populates $1, $2, $3, so I guess neither answers the OP.