You may simply be working too hard. If your format is just as described, and you don't have the TAB character anywhere in your data, you could probably just use something like (untested):
while (my $line = <INFILE>) { my ($date, $description, $amount) = split /\t/, $line; if (defined $amount) { print OUTFILE $amount; } else { # Amount not found... } }
If you're really wanting to use a regular expression, though, something like this might be more appropriate:
while (my $line = <INFILE>) { if ($line =~ /(-?\$\d*\.\d*)/) { print OUTFILE $1, "\n"; } else { # Amount not found... } }
In the regex, '-?' means "Maybe a minus sign". I left out the square brackets because they didn't really add anything just make a mess of things.
...roboticus
Update: Corrected square bracket comment. (Kudos to GrandFather for the catch.)
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: REGEX Frustration
by roboticus
in thread REGEX Frustration
by RobertJ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |