From: Pit Capitain Date: 2002-05-20T08:14:55+09:00 Subject: Re: Need Multiline Regexp Help Hi Jim, > I am having trouble understanding > what is happening. Can someone help? > > irb(main):003:0> s="fred\nhello" > "fred\nhello" > irb(main):005:0> s.scan(/f.*[^l]/m) > ["fred\nhello"] ## I thought [^l] would not match 'l' The RE searches for an "f" followed by as many characters (-> "red\nhell") followed by one character that isn't "l" (-> "o"). > irb(main):006:0> s.scan(/(f.*)[^l]/m) > [["fred\nhell"]] ## Again, why the match of 'll' See above. It returns the sub-expression, which is everything up to the last "o". > irb(main):009:0> s.scan(/(f.*)[^lo]/m) > [["fred\nh"]] ## Why adding a second char changes the result? In this RE, the last character should be something which is neither "l" nor "o", so this matches the "e" in hello. The sub-expression in parenthesis returns everything up to this last character, which is "fred\nh". If you want to look for an "f" followed by anything but an "l", you�d have to specify /f[^l]*/. Hope that helps. Regards, Pit