in reply to Regex for multiple numbers between double quotes
I think a Text::CSV approach as outlined by Athanasius here might be better in general, but if you're stuck with using regexes, here's another approach.
I'm also stumped by the "replace by what?" question, so this solution just uses a list of one-for-one replacement strings. Note that due to the arcane demands of Windose, what appears as [^^\"] below is really the [^"] complemented character set, and \" is really " for the same reason. Note also that Perl version 5.10+ is needed due to the use of the \K operator; I think a work-around would be | a work-around is fairly simple for pre-5.10 Perls.
(For reasons of display and comparison, (almost) all the replacement strings are the same length as the sub-strings replaced, but there's no requirement that this be so.)c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my $old = '\"\", \"2.90\", \"3.00\", \"3.10\", \"3.20\", \"3.30\", \"3.40\", +\"4.20\", \"5v\"'; print qq{'$old'}; ;; my @repl = ('', qw(9.11 9.21 9.31 9.41 9.51 9.61 9.71 6wxyz)); my $new = replace_from_list($old, @repl); print qq{'$new'}; ;; ;; sub replace_from_list { my ($string, @list) = @_; ;; my $i = 0; $string =~ s{ \G (?: \" , [^^\"]*)? \" \K [^^\"]* (?= \") } {$repl[ $i++ ]}xmsg; $i == @list or die qq{replacement list mismatch}; return $string; } " '"", "2.90", "3.00", "3.10", "3.20", "3.30", "3.40", "4.20", "5v"' '"", "9.11", "9.21", "9.31", "9.41", "9.51", "9.61", "9.71", "6wxyz"'
Give a man a fish: <%-{-{-{-<
|
|---|