teaching machines

CS 330 Lecture 4 – Regular Expressions

January 29, 2014 by . Filed under cs330, lectures, spring 2014.

Agenda

TODO

While You’re Waiting

State Machines

Code

show_matches.rb

#!/usr/bin/env ruby

txt = IO.read('eg.txt')
puts txt.scan(/[0-9]/)
puts '--------------'
puts txt.scan(/\S+@\S+/)
puts '--------------'
puts txt.scan(/\.\s+[a-z]/)
puts '--------------'
puts txt.scan(/<b>.*<\/b>/)
puts '--------------'
puts txt.scan(/<.*?>/)

eg.txt

asdf asdf 1 234 456
asdfkl sdf kdfklads f <b>56</b>
johnch@uwec.edu
asdfk foo@foo.com
The dog is <b>luscious</b>. The cat is blah. those who walk on rainbows peak at middle age.

Haiku

Can brains handle X?
Brains have handled X for years
They’re on to Y now

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *