# String scan on html

**URL:** <https://www.ruby-forum.com/t/string-scan-on-html/49276>\
**Category:** Ruby\
**Created:** [December 2, 2005, 12:37am UTC](https://www.ruby-forum.com/t/string-scan-on-html/49276 "2005-12-02T00:37:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruno.bazzani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@bruno.bazzani](https://www.ruby-forum.com/u/bruno.bazzani)\
**Post date:** [December 2, 2005, 12:37am UTC](https://www.ruby-forum.com/t/string-scan-on-html/49276/1 "2005-12-02T00:37:07Z")

</div>

Please consider the following code:

require ‘net/http’  
Net::HTTP.start(‘[weather.gmdss.org](http://weather.gmdss.org)’) do |http|  
response = http.get(‘/III.html’)  
response.body.scan(/\<a.\*a\>/) {|link| puts “#{link}\n\n”}  
end

I expect to have each html link printed separately but this is true only  
for the first three. The others are grouped together in two group.

## This is what I get.

[![WMO]()](http://www.wmo.ch/index-fr.html)

[![MF]()](http://www.meteo.fr)

[![JCOMM]()](http://www.jcommweb.net/)

HOME PAGE  
METAREA I  
METAREA  
II  
**METAREA III**  
[cut]

## HOME PAGE - **III**

  
[cut]

Any help will be really appreciated.

Bruno

---

<div class="post-metadata">

**Author:** ![bruno.bazzani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@bruno.bazzani](https://www.ruby-forum.com/u/bruno.bazzani)\
**Post date:** [December 2, 2005, 12:41am UTC](https://www.ruby-forum.com/t/string-scan-on-html/49276/2 "2005-12-02T00:41:09Z")

</div>

response.body.scan(/\<a.\*?a\>/)

(Note the question mark.)

Read up on greedy versus non-greedy matching in regular expressions.

---

<div class="post-metadata">

**Author:** ![bruno.bazzani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@bruno.bazzani](https://www.ruby-forum.com/u/bruno.bazzani)\
**Post date:** [December 2, 2005, 1:13am UTC](https://www.ruby-forum.com/t/string-scan-on-html/49276/3 "2005-12-02T01:13:30Z")

</div>

> Read up on greedy versus non-greedy matching in regular expressions.

Thanks !  
No need to say that I’m a newbie. I’m coding with the pickaxe manual on  
my  
side and yes … I miss the point: sorry.

But why did it work for the first three occurrences ?

Bruno

---

<div class="post-metadata">

**Author:** ![bruno.bazzani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@bruno.bazzani](https://www.ruby-forum.com/u/bruno.bazzani)\
**Post date:** [December 2, 2005, 2:18am UTC](https://www.ruby-forum.com/t/string-scan-on-html/49276/4 "2005-12-02T02:18:12Z")

</div>

On Dec 2, 2005, at 0:10, Bruno Bazzani wrote:

> > Read up on greedy versus non-greedy matching in regular expressions.
> 
> Thanks !  
> No need to say that I’m a newbie. I’m coding with the pickaxe  
> manual on my side and yes … I miss the point: sorry.
> 
> But why did it work for the first three occurrences ?

Because they’re on their own line to begin with, and regular  
expressions (by default) work on a line-by-line basis.

You will probably also want to include the multiline option in your  
expression, otherwise you’ll fail in situations like this as well:

 

un-necessary whitespace

 

matthew smillie.
