From: "Jesús Gabriel y Galán" Date: 2009-12-14T19:16:24+09:00 Subject: Re: problem with trivial regular expression 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 = " fajljsfjaosfohttp://www.marca.comjafosjodfahttp://www.as.comjfoaasjofja" => " fajljsfjaosfohttp://www.marca.comjafosjodfahttp://www.as.comjfoaasjofja" irb(main):003:0> s.scan(/http\:\/\/.+?\.com/) => ["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.