From: Pit Capitain Date: 2002-05-20T08:39:07+09:00 Subject: Re: Need Multiline Regexp Help Hi Jim, > Actually, I would like to match "fred" followed by > anything but "fred". In other words, my string is of the form > > < fred > some line 1 > some line 2 > fred > some line x > some line y > fred > ... > EOF > > I would like the string broken into array elements with > (in this case) three lines per element. > > So, I am not sure how to look for multiple characters /fred[^fred]/ > will not work, of course. In this case I'd use String#split to split the string at fred: irb(main):001:0> s = < s.split(/fred/) ["", "\nsome line 1\nsome line 2\n", "\nsome line x\nsome line y\n", "\n...\n"] This doesn't yield the fred lines, 'cause the fred is consumed by the RE, so try with "zero-width positive lookahead": irb(main):012:0> s.split(/(?=fred)/) ["fred\nsome line 1\nsome line 2\n", "fred\nsome line x\nsome line y\n", "fred\n ...\n"] This splits the String at "fred"s, but doesn't consume the "fred"s. Regards, Pit