InfiniteSilence has asked for the wisdom of the Perl Monks concerning the following question:
And I get:#!/usr/bin/perl -w use strict; my $mm=qq(\"000.E+3\",\"\",\"\",\"\",\"QCA-086_2\",\"-1\",\"P\",\"FALS +E\"); my @p = ($mm=~m/(\"[A-Za-z0-9_\-,.+]+\")/g); print map {qq($_\n)} @p; 1;
When I try and make the match optional:"000.E+3" "," "," "," "," "," ","
I get:#!/usr/bin/perl -w use strict; my $mm=qq(\"000.E+3\",\"\",\"\",\"\",\"QCA-086_2\",\"-1\",\"P\",\"FALS +E\"); my @p = ($mm=~m/(\"(?:[A-Za-z0-9_\-,.+]+)?\")/g); print map {qq($_\n)} @p; 1;
Which is what I wanted. I understand that in the first case the regex failed on the second element of $mm but shouldn't it have continued on to the end of the string? Second, where did the comma characters in the output come from?"000.E+3" "" "" "" "QCA-086_2" "-1" "P" "FALSE"
Celebrate Intellectual Diversity
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex match in list context
by flounder99 (Friar) on Oct 02, 2003 at 19:07 UTC | |
|
•Re: regex match in list context
by merlyn (Sage) on Oct 02, 2003 at 19:01 UTC | |
|
Re: regex match in list context
by delirium (Chaplain) on Oct 02, 2003 at 18:59 UTC | |
|
Re: regex match in list context
by Aristotle (Chancellor) on Oct 02, 2003 at 20:45 UTC | |
by Anonymous Monk on Oct 02, 2003 at 20:52 UTC | |
by Aristotle (Chancellor) on Oct 02, 2003 at 20:55 UTC |