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 ...
Get Programming Ruby 3.3 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.