Why use group matching? Why not just divide by "//", either as a regular expression, or as a simple string?
use strict;
my $str = 'abc//def//ghi';
my $short = 'abc';
print "The first:\n";
my @groups = split(/\/\//, $str, 2);
foreach my $val (@groups) {
print "$val\n";
}
print "The second:\n";
@groups = split(/\/\//, $short, 2);
foreach my $val (@groups) {
print "$val\n";
}
gives
The first:
abc
def//ghi
The second:
abc
[EDIT: fixed return max. 2 groups]
source
share