Class: Regexp
Class Method Summary collapse
- .new_escaped(*args) ⇒ Object
- .properly_nested(left_delim, right_delim, start_anywhere = true, ext = "") ⇒ Object
- .quoted_string ⇒ Object
- .whole_string(regex) ⇒ Object
Instance Method Summary collapse
Class Method Details
.new_escaped(*args) ⇒ Object
609 610 611 |
# File 'lib/rubyhacks.rb', line 609 def self.new_escaped(*args) new(escape(*args)) end |
.properly_nested(left_delim, right_delim, start_anywhere = true, ext = "") ⇒ Object
596 597 598 599 600 601 602 |
# File 'lib/rubyhacks.rb', line 596 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 ⇒ Object
603 604 605 |
# File 'lib/rubyhacks.rb', line 603 def self.quoted_string /"(?:\\\\|\\"|[^"\\]|\\[^"\\])*"|'(?:\\\\|\\'|[^'\\]|\\[^'\\])*'/ end |
.whole_string(regex) ⇒ Object
606 607 608 |
# File 'lib/rubyhacks.rb', line 606 def self.whole_string(regex) new("\\A#{regex.to_s}\\Z") end |
Instance Method Details
#verbatim ⇒ Object
593 594 595 |
# File 'lib/rubyhacks.rb', line 593 def verbatim self.inspect.sub(/\A\//,'').sub(/\/[mix]*\Z/,'') end |