On 04/20/2012 11:29 AM, Simon Wistow wrote:


 just fine. However I'm trying to add a new opcode DAT which can take any
 number of operands

     DAT 0x170, "Hello ", 0x2e1 (, ....)

 and it fails there.

 Running this

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

 on

      FOO A, B, C

 results in @operands being ('A', 'C');


i would take a simpler approach. just grab the whole optional string
after the opcode (all the operands) and then split that on comma (and
optional trailing whitespace). why try to do it all in one regex when
that is simpler and should work fine. so your last regex component would
be something like \s*(.+)? or \s*(.*)

uri






Reply via email to