From: "Ara.T.Howard" Date: 2003-12-04T02:37:06+09:00 Subject: Re: Some Regexp On 3 Dec 2003, Dmitry N Orlov wrote: > Date: 3 Dec 2003 02:28:24 -0800 > From: Dmitry N Orlov > Newsgroups: comp.lang.ruby > Subject: Some Regexp > > I want to get array from file like this: > > TEXT1 > some text, tabs, CRLF etc 1 > TEXT2 > TEXT1 > some text, tabs, CRLF etc 2 > TEXT2 > TEXT1 > some text, tabs, CRLF etc 3 > TEXT2 > ....... > > Array mast constists of "some text, tabs, CRLF etc 1", "some text, > tabs, CRLF etc 2" > > Can You help me? all fields are separated by either TEXT2 TEXT1 or TEXT1 as a special case /tmp > cat foo.rb txt = <<-txt TEXT1 some text, tabs, CRLF etc 1 TEXT2 TEXT1 some text, tabs, CRLF etc 2 TEXT2 TEXT1 some text, tabs, CRLF etc 3 TEXT2 txt p(txt.split(%r/(?:TEXT1)|(?:TEXT2$)?TEXT1/iom)[1..-1]) /tmp > ruby foo.rb ["\n some text, tabs, CRLF etc 1\n TEXT2\n ", "\n some text, tabs, CRLF etc 2\n TEXT2\n ", "\n some text, tabs, CRLF etc 3\n TEXT2\n"] note that the first field is dropped, since it is empty. -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================