class Regexp

Public Class Methods

new_escaped(*args) click to toggle source
# File lib/rubyhacks.rb, line 618
def self.new_escaped(*args)
        new(escape(*args))
end
properly_nested(left_delim, right_delim, start_anywhere=true, ext = "") click to toggle source
# File lib/rubyhacks.rb, line 605
def self.properly_nested(left_delim, right_delim, start_anywhere=true, ext = "")
        raise ArgumentError.new("Left and right delimiters (#{left_delim.inspect}, #{right_delim.inspect}) cannot be the same") if left_delim == right_delim
        
        nodelim = "(?<nodelim#{ext}>\\\\\\\\|\\\\\\#{left_delim}|\\\\\\#{right_delim}|[^#{left_delim}#{right_delim}\\\\]|\\\\[^#{left_delim}#{right_delim}\\\\])"
        
        new("#{start_anywhere ? "(?<before#{ext}>#{nodelim}*?)" : ""}(?<group#{ext}>\\#{left_delim}#{start_anywhere ? "\\g<nodelim#{ext}>" : nodelim}*?(?:\\g<group#{ext}>\\g<nodelim#{ext}>*?)*\\#{right_delim})")
end
quoted_string() click to toggle source
# File lib/rubyhacks.rb, line 612
def self.quoted_string
        /"(?:\\\\|\\"|[^"\\]|\\[^"\\])*"|'(?:\\\\|\\'|[^'\\]|\\[^'\\])*'/
end
whole_string(regex) click to toggle source
# File lib/rubyhacks.rb, line 615
def self.whole_string(regex)
        new("\\A#{regex.to_s}\\Z")
end

Public Instance Methods

verbatim() click to toggle source
# File lib/rubyhacks.rb, line 602
def verbatim
        self.inspect.sub(/\A\//,'').sub(/\/[mix]*\Z/,'')
end