From: Justin Collins Date: 2006-08-04T08:00:00+09:00 Subject: Re: Non-greediness in a regex - need some help verifying syn On Aug 3, 2006, at 6:09 PM, Wes Gamble wrote: > I realized I made an error when I did the original post. > > Now my problem is that it won't find any of these occurrences now. > > So @bigstring.scan(/~\^LNK:[\t\r\n]+?\^~/m) isn't returning anything. > My guess is because there are no occurrences of a tab, newline, or line > feed character _immediately_ after ~^LNK. > > If I do /~\^LNK:.*?[\t\r\n]+?.*?\^~/m - that should pick up what I want, > correct? > > Wes > > --Posted via http://www.ruby-forum.com/. Morton Goldberg wrote: > I'm not exactly an expert on regexs, to say the least, but I think .*? > always matches an empty string and is therefore useless. I would try > something like > > @bigstring.scan(/~\^LNK:[^\t\r\n]*[\t\r\n]+?[^\t\r\n]*\^~/m) > > I have not test this. > > Regards, Morton No, that's not true. .*? It will match whatever it needs to get to the next item: irb(main):001:0> "asidjoaisdj".match(/.*?j/)[0] => "asidj" irb(main):002:0> "asidjoaisdj".match(/.*?d/)[0] => "asid" irb(main):003:0> "asidjoaisdj".match(/.*?sdj/)[0] => "asidjoaisdj" Therefore, it should work as Wes expects. -Justin