From: Mike Stok Date: 2002-12-18T02:46:31+09:00 Subject: Re: Multirow slicing In article <06DC40326E25F44682B5FDD8918423034A55AC@uranium.il.kangaroo.net>, Roman Rytov wrote: > Here is a multirow string > > Str = > > > String11 abc string12 > String21 string22 ABC > String31 ABC String32 > > I need to get all text between "abc" and "ABC". Both cases are > interesting: to the first occurrence of ABC and to the second. > So the results would be > > > 1. abc string12 > String21 string22 ABC > > > 2. abc string12 > String21 string22 ABC > String31 ABC Have you looked at the m modifier for Regexps? [mike@ratdog mike]$ irb irb(main):001:0> str = ' irb(main):002:0' irb(main):003:0' String11 abc string12 irb(main):004:0' String21 string22 ABC irb(main):005:0' String31 ABC String32 irb(main):006:0' ' => "\n\nString11 abc string12\nString21 string22 ABC\nString31 ABC String32\n" irb(main):007:0> str =~ /(abc.*?ABC)/ && $1 => nil irb(main):008:0> str =~ /(abc.*?ABC)/m && $1 => "abc string12\nString21 string22 ABC" irb(main):009:0> str =~ /(abc.*ABC)/m && $1 => "abc string12\nString21 string22 ABC\nString31 ABC" Note that in step 7 the m modifier wasn't used so . doesn't match \n. The difference between .* and .*? is that the first will match as much as possible while still allowing the overall match to succeed, the second will match as little as possible (non-greedy) Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA