Sha256: d02d0e9610c23fa3ffe3c652c0a3f0d8e2b47f4d841850764a6ab7d66a29f8f7

Contents?: true

Size: 825 Bytes

Versions: 4

Compression:

Stored size: 825 Bytes

Contents

#
# Regular Expression example
# by Martin Prout.  
# 
# This uses ruby scan
#
# Here we'll load the raw HTML from a URL and search for web-links
#

attr_reader :links, :url

def setup
  size(360, 480)
  @url = "http://processing.org"
  # Load the links
  @links = load_links(url)
  links.uniq! # get rid of the duplicates
  text_font(create_font("Georgia", 16))
end

def draw
  background(0)
  # Display the bare links
  fill(0, 255, 255)
  links.each_with_index do |link, i|
    text(link, 10, 20 + i * 20)
  end
end

def load_links(s)
  # Load the raw HTML
  lines = load_strings(s)
  # Put it in one big string
  all_txt = lines.join('\n')
  all_txt.scan(/
        https?:\/\/
        \w+
        (?: [.-]\w+ )*
        (?:
            \/
            [0-9]{1,5}
            \?
            [\w=]*
        )?
    /ix)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-2.4.4 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.4.3 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.4.2 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.4.1 samples/processing_app/topics/advanced_data/regex.rb