Day 8. Pattern Matching

Give me a vigorous hypothesis every time. Without one, there's nothing to do but drown in facts.

—Norman Mailer, Harlot's Ghost

Some of the most common yet perplexing tasks in computing are in the realm of pattern matching, that is, finding information that satisfies a given description. For many pattern-matching tasks, the tool of choice is the regular expression, which we refer to casually as a regex.

What exactly is a pattern? On Day 3 we did some pattern matching on strings, using the String#include? method:

"Hospital".include?("pita")  #-> true

We already know how to find the most concrete and simple-minded kind of pattern, which is an exact substring. Maybe we'd like to know whether a string contains a date in ...

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.