Regex help

Uri Guttman uri at stemsystems.com
Fri Apr 20 23:34:01 BST 2012


On 04/20/2012 05:23 PM, Simon Wistow wrote:
> On Fri, Apr 20, 2012 at 08:37:42PM +0000, Anthony Lucas said:
>>
>> How about a parser using Regexp? Parser::MGC?
>>
>> You can implement a proper parser, or just a few staged regexp, or anything in-between.
>
> I ended up just doing this
>
>      my ($label, $op, $operands) = $line =~ m!
>          ^
>          (?::(\w+)      \s+)? # optional label
>          ([A-Za-z]+)    \s+   # opcode
>          (.+)           \s*   # operands
>          $
>      !x;
>      # TODO this won't cope with commas inside quotes
>      # e.g DAT 0x20, "hello, goodbye", 0x10
>      my @operands = split /\s*,\s*/, ($operands || "");
>

and that is exactly what i suggested in another post (haven't seen it 
hit the list yet). :)

you can use text::balanced to handle quoted strings.

uri


More information about the london.pm mailing list