A Gentle Introduction

Even if you haven’t used regular expressions before, you might have used wildcards. On the command line, for example, we can use patterns like dog-*.jpg to match many files (in this case, matching things like dog-jumping.jpg, dog-2.jpg, dog-large.jpg, and so on for infinitely more files).

These wildcards work because the * character is understood to have a special meaning. It doesn’t represent the literal *, but instead represents any and all characters.

Regular expressions work in exactly the same way. The difference is that they extend the list of these special characters significantly, allowing you greater power and flexibility. Wildcards allow you to say “I want to match this specific character” and “I want to match ...

Get Text Processing with Ruby 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.