Thank you for your answer, but I think I have expressed myself wrong so I will post my entire code If you can help me. I want to open a file, read the values between the double quotes and replace some numbers from this file with their corresponding value from the first line. This is my code:

#!/usr/bin/perl # matchtest2.plx use warnings; use strict; open (my $original, '<', 'data.txt') or die $!; open (my $fh, '>', 'output.txt') or die $!; while (my $line = <$original>) { if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/) { my $replace = $1; $line =~ s/[^.]00/$replace/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace1 = $2; $line =~ s/01/$replace1/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace2 = $3; $line =~ s/02/$replace2/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace3 = $4; $line =~ s/03/$replace3/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace4 = $5; $line =~ s/04/$replace4/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace5 = $6; $line =~ s/05/$replace5/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace6 = $7; $line =~ s/06/$replace6/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace7 = $8; $line =~ s/07/$replace7/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace8 = $9; $line =~ s/08/$replace8/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace9 = $10; $line =~ s/09/$replace9 /g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace10 = $11; $line =~ s/[^.]10/$replace10/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace11 = $12; $line =~ s/11/$replace11/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace12 = $13; $line =~ s/12/$replace12 /g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace13 = $14; $line =~ s/13/$replace13/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace14 = $15; $line =~ s/14/$replace14/g; } if ($line =~ m/\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", +\"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"( +.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\", \"(.*?)\"/g) { my $replace15 = $16; $line =~ s/15/$replace15/g; } print {$fh} $line; } close $original; close $fh;

and this is my original file(just a short version, the actual one has thousands of numbers)

"", "2.90", "3.00", "3.10", "3.20", "3.30", "3.40", "3.50", "3.60", "3 +.70", "3.80", "3.90", "4.00", "4.10", "4.20", "5v" 09 12 12 10 08 08 10 07 10 09 08 08 + 06 10 10 08 09 11 08 10 07 10 11 00 00 10 12 13 10 09 08 08 06 10 01 + 08 09 11 08 10 07 10 11 12 13 05

I have to replace for example 00 with the value between the first "" so 00 would be empty string, 01 with the value of the second "2.90" so 01 would become 2.9 and so on... Thank you very much for all your help


In reply to Re^2: Regex for multiple numbers between double quotes by Akatsuki
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.