What you describe is a CSV (character separated value) file and there are a plethora of modules available to handle that format for you. A good starting point is Text::CSV. Using such a module your problem turns into:

use strict; use warnings; use Text::CSV; my $dataStr = <<DATA; 1/1/1923\tFirst entry\t-23.45 2/2/1924\t"Second entry with a long multi-line description. This is parsed fine using Text::CSV, but I bet your regex chokes."\t23 +.23 DATA my $csv = Text::CSV->new({sep_char => "\t", binary => 1}); open my $dataIn, '<', \$dataStr; while (my $row = $csv->getline($dataIn)) { my ($date, $description, $value) = @$row; print "Value is $value\n"; } close $dataIn;

Prints:

Value is -23.45 Value is 23.23

As an aside the regex magic you want is the ? modifier:

use strict; use warnings; use Text::CSV; my $dataStr = <<DATA; 1/1/1923\tFirst entry\t-23.45 2/2/1924\t"Second entry with a long multi-line description. This is parsed fine using Text::CSV, but I bet your regex chokes."\t23 +.23 DATA open my $dataIn, '<', \$dataStr; while (my $line = <$dataIn>) { next if $line !~ /(-?\d*\.\d*)/; print "Value is $1\n"; } close $dataIn;

Prints:

Value is -23.45 Value is . Value is .

which you will note still fails in nasty ways because the regex isn't near sufficient to extract the data you want. However, there are a huge number of errors in the regex you show so you absolutely must go read some of the regex documentation: perlretut, perlre and perlreref for a start.

True laziness is hard work

In reply to Re: REGEX Frustration by GrandFather
in thread REGEX Frustration by RobertJ

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.