From: "Jesús Gabriel y Galán" Date: 2010-11-19T22:33:42+09:00 Subject: Re: Multi-line regular expression match question On Fri, Nov 19, 2010 at 1:42 PM, Guillermo Riojas wrote: > Hi, > > I have been trying to create a solid regular expression to match a > possible multi-line expression without success. So after several hours i > almost got there but not the point i would like, hoping somebody can > point me in the right direction. > Here is an example i am dealing with: > > 01xxxxxxxxxxxxxx > |-: > <20>ABCD > <30>edfghi212 > -| > |-: > <20>EFGH > <30>hjkli3232 > -| > 89xxxxxxxxxxxxx > > I need to match anything that is enclosed in between "|-:" and "-|" > So far i've got "/^\{\|-:$.*^-\|$/m" , this one is greedy, returning the > complete set, instead of each match, i just haven't figure out how to > make it reluctant enough to return one by one. > > The returned matches expected must be something like this: > > 1: > |-: > <20>ABCD > <30>edfghi212 > -| > > 2: > |-: > <20>EFGH > <30>hjkli3232 > -| > > Currently is returning: > 1: > > |-: > <20>ABCD > <30>edfghi212 > -| > |-: > <20>EFGH > <30>hjkli3232 > -| > > > Any suggestion is greatly appreciated. > And finally, any good regular expressions book ?? =) irb(main):018:0> s =<ABCD irb(main):022:0" <30>edfghi212 irb(main):023:0" -| irb(main):024:0" |-: irb(main):025:0" <20>EFGH irb(main):026:0" <30>hjkli3232 irb(main):027:0" -| irb(main):028:0" 89xxxxxxxxxxxxx irb(main):029:0" EOF => "01xxxxxxxxxxxxxx\n|-:\n<20>ABCD\n<30>edfghi212\n-|\n|-:\n<20>EFGH\n<30>hjkli3232\n-|\n89xxxxxxxxxxxxx\n" irb(main):036:0> s.scan(/(\|-:.*?-\|)/m) => [["|-:\n<20>ABCD\n<30>edfghi212\n-|"], ["|-:\n<20>EFGH\n<30>hjkli3232\n-|"]] Jesus.