Reputation: 2216
I have a line that containes multiple instances of square bracketed data.
[data 1] junk [data 2] junk,junk [data 3] junk [data 4]
Does any one have a goo regex? So I can use
print $1,$2,$3,$4;
Thanks!
Upvotes: 2
Views: 2813
Reputation:
If all your looking for is a quick printout, this should do it ..
$s = q( [data 1] junk [data 2] junk,junk [data 3] junk [data 4] );
print join(', ', @{[$s =~ /\[(.*?)\]/g]}), "\n";
Upvotes: 1
Reputation: 14222
my $s = "[data 1] junk [data 2] junk,junk [data 3] junk [data 4]";
my ($one, $two, $three, $four) = $s =~ /\[([^\]]*)\]/g;
print $one, $two, $three, $four;
Upvotes: 4