On Feb 3, Massimiliano Mirra said:

>dividers = ['\|\|', '&&', ';']
>divs = dividers.collect {|div| "(#{div})"}.join('|')
>SPLIT_RE = /([^#{divs}]+)|#{divs}/
'ls || cd dir; grep word * && beep'.scan(SPLIT_RE).flatten.compact

That regex does not do what you think it does...

  /([^jeff]+)|jeff/

does not mean "one or more non-jeff's in a row, OR jeff", but rather "one
or more non-j's, non-e's, and non-f's in a row, OR jeff".

>'ls || cd dir; grep "word; sentence" && beep'

This is a job for a more explicit parser -- one that recognizes quotes and
escapes and all.

I come from a Perl background, so I apologize if my Ruby isn't quite as
idiomatic as many might be used to.

  SPLIT_RE = %r{
    \|\|
      |  
    ;
      |
    &&
      |
    (?= . )
    [^|;&"]*
    (?:
      (?:
        \| (?! \! )
          |
        & (?! & )
          |
        " (?: [^\\"]* (?: \\. [^\\"]* )* ) "
      )
      [^|;&"]*
    )
  }x;

  str.scan(SPLIT_RE).flatten.compact.each{ |x| puts "<#{x}>" }

The regex is lengthy.  I left out single-quote support, but you can
probably see how to include that (model it after the double-quote support
section).  It's generally not easy to mechanically construct such a regex,
but I suppose it can be done (and I'm the type of person who'd do it ;) ).

-- 
Jeff "japhy" Pinyan      japhy / pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.