in reply to Re: Parsing issue
in thread Parsing issue

Wouldn't this break also on something like this?
$string = q/allow:"bad param:doh!" deny:test2/;

Not sure how I'd go about parsing this, but perhaps you could preprocess the string, replacing all the quoted text with placeholders, then splitting on spaces?

-- Dan

Replies are listed 'Best First'.
Re: Re: Re: Parsing issue
by jj808 (Hermit) on Oct 08, 2002 at 12:56 UTC
    Try this:
    #! /usr/bin/perl my $string = q/allow:test1,"@test, 2 " deny:test3,test4 password:"123 + 456doh:"/; while ($string =~ s/(\w+):((\w+|"[\w ,:@]+")(,\s*(\w+|"[\w ,:@]+"))*)\ +s*($|(?=\w+:))//) { print "Argument: $1\n"; my $paramlist = $2; while ($paramlist =~ s/(\w+|"[\w ,:@]+")\s*,*\s*//) { print " Param: $1\n"; } }
    However the regexp is starting to get a bit complicated - Text::ParseWords looks like a neater solution.

    JJ