From: Robert Klemme Date: 2006-03-29T05:58:55+09:00 Subject: Re: Regexp to match strings that _don't_ being with a string Wes Gamble wrote: > Thanks, that makes sense since the lookahead doesn't "consume" right? Right. In this case an alternation works, too: p %w{abcd xyz as}.map {|s| /^(?!abc|xyz)/=~s} => [nil, nil, 0] De Morgan's Law comes to mind: not a and not b <=> not(a or b) :-) Kind regards robert > WG > Joel VanderWerf wrote: >> Wes Gamble wrote: >>> I have a new wrinkle. >>> >>> Now I want to match any line that doesn't have "xyz" or "abc" at the >>> beginning of the line. >>> >>> Is there a way to "AND" together the input to the negative lookahead >>> assertion? >> For lookaheads, you can get AND by concatenating: >> >> >> irb(main):001:0> /^(?!abc)(?!xyz)/ =~ "abc" >> => nil >> irb(main):002:0> /^(?!abc)(?!xyz)/ =~ " abc" >> => 0 >> irb(main):003:0> /^(?!abc)(?!xyz)/ =~ "xyz" >> => nil >> irb(main):004:0> /^(?!abc)(?!xyz)/ =~ " xyz" >> => 0 > >