new

Regexp.new(string, [options [, kcode]]) â regexp
Regexp.new(regexp) â regexp
Regexp.compile(string, [options [, kcode]]) â regexp
Regexp.compile(regexp) â regexp
Class Public methods

Constructs a new regular expression from pattern, which can be either a String or a Regexp (in which case that regexp's options are propagated), and new options may not be specified (a change as of Ruby 1.8).

If options is a Fixnum, it should be one or more of the constants Regexp::EXTENDED, Regexp::IGNORECASE, and Regexp::MULTILINE, or-ed together. Otherwise, if options is not nil or false, the regexp will be case insensitive.

When the kcode parameter is `n' or `N' sets the regexp no encoding. It means that the regexp is for binary strings.

r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
r2 = Regexp.new('cat', true)     #=> /cat/i
r3 = Regexp.new(r2)              #=> /cat/i
r4 = Regexp.new('dog', Regexp::EXTENDED | Regexp::IGNORECASE) #=> /dog/ix
doc_ruby_on_rails
2015-05-05 04:09:14
Comments
Leave a Comment

Please login to continue.