module Capybara::Helpers

def to_regexp(text, exact: false, all_whitespace: false, options: nil)

Returns:
  • (Regexp) - Regexp to match the passed in text and options

Parameters:
  • options (Fixnum, Boolean, nil) -- Options passed to Regexp.new when creating the Regexp
  • exact (Boolean) -- (false) Whether or not this should be an exact text match
  • text (String) -- Text to escape
def to_regexp(text, exact: false, all_whitespace: false, options: nil)
  return text if text.is_a?(Regexp)
  escaped = Regexp.escape(text)
  escaped = escaped.gsub("\\ ", "[[:blank:]]") if all_whitespace
  escaped = "\\A#{escaped}\\z" if exact
  Regexp.new(escaped, options)
end