Sha256: c26390850f49923b5f336a7b42f3f304ab19fd73bb4a65bfeb1335a991c2c2e6

Contents?: true

Size: 820 Bytes

Versions: 6

Compression:

Stored size: 820 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

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.6.2 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.6.1 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.6.0 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.5.1 samples/processing_app/topics/advanced_data/regex.rb
ruby-processing-2.5.0 samples/processing_app/topics/advanced_data/regex.rb