|
|
| Welcome to the Monastery | |
| PerlMonks |
Capturing all instances of a repeating sub-pattern in regexby wanna_code_perl (Monk) |
| on Nov 16, 2012 at 17:44 UTC ( #1004225=perlquestion: print w/ replies, xml ) | Need Help?? |
|
wanna_code_perl has asked for the
wisdom of the Perl Monks concerning the following question:
Hello monks, An aspect of this regex has me stumped:
Of course, this will only return the description and last number in ($1, $2) since Perl only keeps the last successful pattern match in a quantifier. I can cut/paste line 2 of the regexp a bunch of times to account for some arbitrary maximum number of numbers and it works, but it's sort of ugly. Data Format
Note that the data may contain arbitrary newlines between lines, and whitespace at the end of lines. The numbers will sometimes include units, which will always be a literal ' PSI'. The basic pattern is (Description, number, ...). The pattern comes into Perl as a blob. The Question That's in Here SomewhereI could also just split /(\s*\n)+/ or such and iterate on lines building up records as I go, but is there no way I can build @r with one regex? I know, $me->has('cake') && $me->eat('cake'); :-)
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||