From: "yermej@..." Date: 2007-06-29T13:30:04+09:00 Subject: Re: Help with regular expression On Jun 28, 11:11 pm, "yer...@gmail.com" wrote: > On Jun 28, 10:27 pm, "tou...@gmail.com" wrote: > > > > > Like I said it has to be a regular expression, nothing else, any > > ideas? > > > On Jun 28, 11:24 pm, "Stephen Ball" wrote: > > > > On 6/28/07, dbl...@wobblini.net wrote: > > > > > Hi -- > > > > > On Fri, 29 Jun 2007, Jesse Hk wrote: > > > > > > Am I missing something here? Why not just test for equality? > > > > > > irb(main):001:0> "foo" == "foo" > > > > > => true > > > > > irb(main):002:0> "foo" == "bar" > > > > > => false > > > > > That doesn't cover the case where the string includes the substring > > > > "bar" but also includes other characters. > > > > > David > > > > In that case it still works, so we have: > > > > "foo" => "foo" > > > > irb(main):001:0> "foo" == "foo" > > > => true > > > > "bar " => nil > > > > irb(main):002:0> "foo" == "bar" > > > => false > > > > "foobar" => nil > > > > irb(main):003:0> "foo" == "foobar" > > > => false > > > > -- Stephen > > As Axel said, you need to use a regex with negative lookahead. This > should work: > /b(?!ar)/ > as long as whichever language/system you're using supports it. Maybe > there's a better group or forum for your question if you're not using > Ruby. > > I would have thought this would work: > /.*(?!bar)/ > but it doesn't in Ruby. I would take that to mean 0 or more of any > character not followed by bar, but I guess that's not the case. I > (obviously) don't understand negative lookahead all that well. Can > anybody explain? > > Jeremy Sorry, but I was wrong. I /b(?!ar)/ isn't right because it would only match a string if it contains a 'b'. I would have thought /.*(?!bar)/, but as I said, that doesn't work in Ruby and probably shouldn't now that I've thought about it more. Probably just ignore everything I've said except for the fact that you'll need negative lookahead. I think. Oh, and the part about asking in a more appropriate group if you aren't really looking for a Ruby regex. Jeremy