Chapter 8Regular Expressions
We spend much of our time in Ruby working with strings, so it seems reasonable for Ruby to have great tools for working with those strings. As we’ve seen, the String class itself is no slouch—it has more than 100 methods. But it still can’t do everything on its own. For example, we might want to see whether a string contains two or more repeated characters, or we might want to replace every word longer than fifteen characters with its first five characters and an ellipsis. This is when we turn to the power of regular expressions.
Regular expressions are powerful and are used in many languages besides Ruby. In this chapter, we’ll cover the basics of what regular expressions can do in Ruby; later, in Regular Expressions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access