Regular Expressions

Regular expression literals are objects of type Regexp. They are created explicitly by calling Regexp.new or implicitly by using the literal forms, /_pattern_/ and %r{_pattern_}. The %r construct is a form of general delimited input as described in General Delimited Input.

/pattern/ /pattern/options %r{pattern} %r{pattern}options Regexp.new("pattern" <, options>)

options is one or more of i (case insensitive), o (substitute once), m (matches newline), and x (allow spaces and comments). You can additionally override the default encoding of the pattern with n (no encoding-ASCII), e (EUC), s (Shift_JIS), or u (UTF-8).

Within a regular expression, each entry in the following table matches the characters described in its description. ...

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.