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

If you can cope with an array, something as simple as /([^:]+)+/g should do the trick.

my $c='aaa:bbb'; my @arr = $c =~ /[^:]+/g; use Data::Dumper; print Dumper \@arr; __END__ $VAR1 = [ 'aaa', 'bbb' ]; --- my $c='aaa:bbb:foo:bar'; my @arr = $c =~ /[^:]+/g; use Data::Dumper; print Dumper \@arr; __END__ $VAR1 = [ 'aaa', 'bbb', 'foo', 'bar' ];

Update: Simplified the regex, as per Sidhekin suggestion.

--
David Serrano

  • 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 ikegami (Patriarch) on Aug 03, 2006 at 17:50 UTC
    When given 'aaa::bbb', your regexp only returns two items.