From: Benoit Daloze Date: 2009-12-14T19:20:18+09:00 Subject: Re: problem with trivial regular expression --00163641748597c529047aad9ec5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable We are quite according in our posts :) This should be the Ruby way, very clear this time ! 2009/12/14 Jes=FAs Gabriel y Gal=E1n > On Mon, Dec 14, 2009 at 11:06 AM, David Villa wrote= : > > > > hi ,sorry for my english. > > > > I am trying to remember the use of regular expressions and i have a > > problem with this : > > > > i had a text with diferents strings, for example, url , like this : > > > > fajljsfjaosfohttp://www.marca.comjafosjodfahttp://www.as.comjfoaasjofja > > > > i want to extract the diferents url but i try with : > > /(http\:\/\/.+com)/ it returns a long match: > > > > > > > > 1. http://www.marca.comjafosjodfahttp://www.as.com > > > > > > how can i group this in 2 diferents matchs? example : > > 1- http://www.marca.com > > 2- http://www.as.com > > > > > > thanks > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > What you are missing is the non-greedy modifier (?) for the +: > > irb(main):001:0> s =3D " > fajljsfjaosfohttp://www.marca.comjafosjodfahttp://www.as.comjfoaasjofja" > =3D> " > fajljsfjaosfohttp://www.marca.comjafosjodfahttp://www.as.comjfoaasjofja" > irb(main):003:0> s.scan(/http\:\/\/.+?\.com/) > =3D> ["http://www.marca.com", "http://www.as.com"] > > (I also added an extra \. before com, to match a ".com" and not "com" > only). Then, scan helps you going through the full string retrieving > matches. > > Hope this helps, > > Jesus. > > --00163641748597c529047aad9ec5--