Sha256: f34b5cd2bd0d5b035fc9aae0bd1019b5b411c864c6e26eca4a377d2c57b52ada

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

=to_regexp

Basically a safe way to convert strings to regexps (with options).

    str = "/finalis(é)/im"
    old_way = eval(str)     # not safe
    new_way = str.to_regexp # provided by this gem
    old_way == new_way      # true

You can also treat strings as literal regexps. These two are equivalent:

    '/foo/'.to_regexp                                       #=> /foo/
    'foo'.to_regexp(:literal => true)                       #=> /foo/
    
If you need case insensitivity and you're using <tt>:literal</tt>, pass options like <tt>:ignore_case</tt>. These two are equivalent:

    '/foo/i'.to_regexp                                      #=> /foo/i
    'foo'.to_regexp(:literal => true, :ignore_case => true) #=> /foo/i

You can get the options passed to <tt>Regexp.new</tt> with <tt>#as_regexp</tt>:

    '/foo/'.to_regexp == Regexp.new('/foo/'.as_regexp) # true

Copyright 2012 Seamus Abshere

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
to_regexp-0.1.1 README.rdoc