Regexp
The Regexp class is the Ruby representation of a regular expression. We discussed the basic syntax of regular expressions at length in Chapter 8, Regular Expressions. Here we focus on the API for the Regexp class itself and then cover some advanced regular expression syntax.
You can create a regular expression using the literal syntax, which is two foreword slashes with the regular expression in the middle, such as /.*rb/. (All the escape sequences and whatnot inside the slashes are discussed in Chapter 8, Regular Expressions. The alternate delimiter %r{...} will also create regular expressions.
The method, Regexp.new(string, options = 0, timeout: nil) creates a new regular expression with the string argument as the pattern. The ...
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