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.

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"'
(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.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Regex for multiple numbers between double quotes by AnomalousMonk
in thread Regex for multiple numbers between double quotes by Akatsuki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.