From: Jeff 'japhy' Pinyan Date: 2002-02-05T06:59:51+09:00 Subject: Re: bash-like command splitting (for regexp wizards) [posted & mailed] On Feb 4, Massimiliano Mirra said: >On Mon, Feb 04, 2002 at 11:57:23AM +0900, Jeff 'japhy' Pinyan wrote: > >> >dividers = ['\|\|', '&&', ';'] >> >divs = dividers.collect {|div| "(#{div})"}.join('|') > ^ ^ >> 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". > >But that regex is (note parentheses above): > >/([^(\|\|)|(&&)|(;)]+|(\|\|)|(&&)|(;)/ Yes, but [^(\|\|)|(&&)|(;)] is the same as [^()|&;] which means "any character that is not (, ), |, &, or ;" -- it doesn't mean "anything that is not || or && or ;". Character classes are just that -- *CHARACTER* classes. Try your code when you've got a single & in your string. You'll lose that single &. 'ls || cd dir &' will come up as 'ls ', '||', ' cd dir ' >> 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{ >> \|\| >> | >> ; >[...] > >Wow. Do you all come to Perl with a degree in Egyptology or do you >get one honoris causa afterwards? :-) I'm sure there's a funny joke in there, but I'm not sure I get it... :) If you're referring to Perl's cryptic syntax, I find it non-cryptic; Perl was tremendously easy for me to learn, and it was my "gateway drug" to other languages (such as C, Python, Ruby, etc.). Learning Perl made it easier for me to learn other languages. >Thanks a lot! I do what I can. -- 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 ** what does y/// stand for? why, yansliterate of course.