From: Dossy Date: 2002-05-20T08:53:21+09:00 Subject: Re: Need Multiline Regexp Help On 2002.05.20, Jim Freeze wrote: > Hi: > > I am trying to collect a set of lines in a string. > The line repeat a pattern, so I figured I could > do a scan with a multi-line regexp to get what > I wanted. But 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' f.* is matching "fred\nhell" -- "o" satisfies [^l]. > irb(main):006:0> s.scan(/(f.*)[^l]/m) > [["fred\nhell"]] ## Again, why the match of 'll' (f.*) matches "fred\nhell" and "o" again satisfies [^l]. > irb(main):009:0> s.scan(/(f.*)[^lo]/m) > [["fred\nh"]] ## Why adding a second char changes the result? Because now "o" doesn't satisfy [^lo] and neither does either of the "ll". Now, the "e" satisfies [^lo] so that (f.*) now matches "fred\nh". > irb(main):010:0> s.scan(/(f.*)[^ol]/m) > [["fred\nh"]] Changing the order doesn't matter. -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)