Object-Oriented Interface

Ruby provides an object-oriented regular expression interface through the Regexp and MatchData classes, as well as several built-in methods of the String class.

Ruby also provides the /.../ and =~ operators to provide a Perl-like operator syntax. The /.../ operator is a synonym for Regexp.new, and =~ is a synonym for String#match. The /.../ operator is commonly used to pass a Regexp object to a method, e.g., "foo, bar, frog".split(/,\s*/).

Get Regular Expression Pocket Reference, 2nd Edition 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.