in reply to Re: Re: parse for string, then print unique
in thread parse for string, then print unique
And the output is -use strict; use warnings; use Data::Dumper; my $str = '"$a $a $a" ab bc "c$d e$f$" c$d "$a $a $a"'; my @uniq = keys %{{map {$_ => 1}($str=~m/("[^"]*\$[^"]*")/g)}}; print Dumper(\@uniq);
Note that I kept the regex simple by not trying to escape the string in the example above. If you want to include escaped strings, the regex becomes more complicated.$VAR1 = [ '"c$d e$f$"', '"$a $a $a"' ];
And the new output -... my $str = '"$a $a $a" ab bc "c$d \"e$f$" c$d "$a $a $a"'; my @uniq = keys %{{map {$_ => 1} ($str=~m/("(?:\\"|.)*?\$(?:\\"|.)*?")/g)}}; ...
$VAR1 = [ '"c$d \\"e$f$"', '"$a $a $a"' ];
|
|---|