module MSFLVisitors::VisitorHelpers
Public Instance Methods
composable_expr_for(regex_as_literal_string)
click to toggle source
# File lib/msfl_visitors/visitor.rb, line 19 def composable_expr_for(regex_as_literal_string) regex_as_literal_string[3..-4] end
escape_es_special_regex_chars(str)
click to toggle source
Note that the ES documentation also indicates that # is a special character that requires escaping and that this behavior is not part of the PERL regex; however Ruby automatically escapes literal hashes when constructing regices
# File lib/msfl_visitors/visitor.rb, line 8 def escape_es_special_regex_chars(str) str.gsub(/([@&<>~])/) { |m| "\\#{m}" } end
regex_escape(escaped_str)
click to toggle source
# File lib/msfl_visitors/visitor.rb, line 12 def regex_escape(escaped_str) esc = Regexp.escape("#{escaped_str.to_s}") exp = escape_es_special_regex_chars "#{esc}" # why you must use #inspect, not #to_s. @link http://ruby-doc.org/core-1.9.3/Regexp.html#method-i-3D-7E %r[.*#{exp}.*] end