I have a line that contain开发者_Go百科es 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!
Use Text::Balanced instead of a regex.
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;
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";
精彩评论