in reply to Complex Splitting
use strict; use warnings; use Data::Dumper; my $str = q{ABC[GHI]XYZ}; my $rxSplit = qr {(?x) # use extended syntax (?: # non-capturing group \[ # literal opening square br. | # or \] # literal closing square br. | # or (?= # look-ahead, a point # followed by [^]]+ # one or more non-closing # square brs. (?: # non-capturing group # then either \[ # literal opening square br. | # or \z # end of string ) # close non-capturing group ) # close look-ahead ) # close non-capturing group }; my @array = split m{$rxSplit}, $str; print Data::Dumper->Dump([\@array], [qw{*array}]);
Here's the output.
@array = ( 'A', 'B', 'C', 'GHI', 'X', 'Y', 'Z' );
On balance, I'd go with the global match, something like holli's or eric256's solutions.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Complex Splitting
by Roy Johnson (Monsignor) on Feb 06, 2007 at 15:54 UTC | |
by johngg (Canon) on Feb 06, 2007 at 18:29 UTC | |
by Roy Johnson (Monsignor) on Feb 07, 2007 at 01:46 UTC |