Regex help

Dagfinn Ilmari Mannsåker ilmari at ilmari.org
Fri Apr 20 17:13:33 BST 2012


Simon Wistow <simon at thegestalt.org> writes:

> my ($label, $op, @operands) = $line =~ m!
>     ^
>     (?::(\w+)      \s+)? # optional label
>     ([A-Za-z]+)    \s+   # opcode
>     ([^,\s]+) (?:, \s+   # operand
>     ([^,\s]+))*    \s*   # optional second opcode
>     $
> !x;

You could use (?{ push @operands, $^N}) after the operand capture
groups, rather than relying on the returned captures.


-- 
ilmari
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen


More information about the london.pm mailing list