From: Lucas Fialho Date: 2009-11-27T10:37:58+09:00 Subject: Re: Help with regex --0016e6d7e0341821be047950578d Content-Type: text/plain; charset=ISO-8859-1 thanks guys. I did not know about string scan! 2009/11/26 Benoit Daloze > s = "Text1\n > Text2\n > Text3---" > > irb(main):036:0> s.scan( /(\w+?)(?:\n|-+)/ ) > => [["Text1"], ["Text2"], ["Text3"]] > > Usually, it's easier to use scan when you feel your code in the Regexp > gonna > be repeated. > If the text is so simple, you could iterate which String#each_line, and > then > remove any '-' at the end. > > 2009/11/26 Lucas Fialho > > > Hello everyone. > > I'm trying to match the following pattern: > > > > Text1\n > > Text2\n > > Text3--- > > > > Please note that Text3 can contain \n. > > I tried using this regex: > > > > /(.*?)\n(.*?)\n(.*?)---/ > > > > The pattern matches and I have three matches, but they're like this: > > > > match[0] => "Text2\nText3---" > > macth[1] => 'Text2' > > match[2] => 'Text3' > > > > How can I get the first one to be 'Text1' ? > > > --0016e6d7e0341821be047950578d--