in reply to Re: In need of a stupid regex trick
in thread In need of a stupid regex trick

Almost, but it keeps the " around the strings.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Re: In need of a stupid regex trick
by bart (Canon) on Jan 04, 2004 at 21:51 UTC
    my @list = grep defined, $str=~/"([^"]*)"|(\S+)/g;
      Great minds think alike (beat you by one minute)

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Re: Re: In need of a stupid regex trick
by demerphq (Chancellor) on Jan 05, 2004 at 03:22 UTC

    Oops. (still untested...)

    my @list=$str=~/((?<=")[^"]*(?=")|\S+)/g

    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      That doesn't work at all; It gives following results:

      $VAR1 = 'one'; $VAR2 = '"two'; $VAR3 = 'three"'; $VAR4 = ' four five '; $VAR5 = '"six'; $VAR6 = 'seven'; $VAR7 = 'eight"'; $VAR8 = 'nine';

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Yeah, greedy quantifiers bite again. :-(

        my @list=$str=~/((?<=")[^"]*?(?=")|\S+)/g

        Shouldn't that do the trick though? (BTW, im trying to get Perl installed on this box.. I may update once I do)


        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi