October 2006
Intermediate to advanced
888 pages
16h 55m
English
Regular expressions can be compiled using the class method Regexp.compile (which is really only a synonym for Regexp.new). The first parameter is required and may be a string or a regex. (Note that if the parameter is a regex with options, the options will not carry over into the newly compiled regex.)
pat1 = Regexp.compile("^foo.*") # /^foo.*/
pat2 = Regexp.compile(/bar$/i) # /bar/ (i not propagated)The second parameter, if present, is normally a bitwise OR of any of the following constants Regexp::EXTENDED, Regexp::IGNORECASE, and Regexp::MULTILINE. Additionally, any non-nil value will have the result of making the regex case-insensitive; we do not recommend this practice.
options = Regexp::MULTILINE || Regexp::IGNORECASE ...
Read now
Unlock full access