|Syntactic Confectionery Delight|
Arbitrary number of captures in a regular expressionby grinder (Bishop)
|on Sep 23, 2007 at 20:33 UTC||Need Help??|
grinder has asked for the
wisdom of the Perl Monks concerning the following question:
I may be overlooking something, but as far as I can tell, given the following strings (simplified from a real-world example, but sufficient for the purpose):
There may be any number of m digit sequences following 'foo'. You cannot group and capture an arbitrary number of times in a single pattern and get back all the captures? That is, the following does not work:
That only captures the final digit group. I think the only way out is to use a pile of code and do something like
There must be a simpler way, but I can't see it right now, worse, that solution doesn't strike me as being particularly well-anchored, that is, following 'foo'.
The chain of m digit+ could be anywhere in string, for instance, after 'bar', and it would be incorrect to match and capture them. Thanks for any suggestions and insights you may have.
• another intruder with the mooring in the heart of the Perl