in reply to splitting a string on pre-defined tags
#!/usr/bin/perl # http://perlmonks.org/?node_id=1215064 use strict; use warnings; use Data::Dumper; my $string='C*ID1*Mac*C release for EA\'s D*ID1*Spore1 game*D; D*ID1*S +pore 1*D is better than D*ID2*Spore 2 game*D.'; my @fields; push @fields, $& while $string =~ /\b([A-Z])\*.*?\*\1\b/g; print Dumper \@fields;
Outputs:
$VAR1 = [ 'C*ID1*Mac*C', 'D*ID1*Spore1 game*D', 'D*ID1*Spore 1*D', 'D*ID2*Spore 2 game*D' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting a string on pre-defined tags
by jimpudar (Pilgrim) on May 22, 2018 at 20:43 UTC |