Method: Contentstack::Query#regex

Defined in:
lib/contentstack/query.rb

#regex(field_uid, pattern, options = "") ⇒ Contentstack::Query

Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets. Example:

@query = @stack.content_type('product').query
@query.regex('title', '.*Mobile.*', 'i') # Search without case sensitivity

Parameters:

  • field_uid (String)

    The key to be constrained.

  • pattern (String)

    The regular expression pattern to match.

  • options (String) (defaults to: "")

    Regex options

Returns:



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/contentstack/query.rb', line 85

def regex(field_uid, pattern, options="")
  hash = {
    "#{field_uid}" => {
      "$regex": pattern
    }
  }

  hash["#{field_uid}"]["$options"] = options if !options.empty? || !options.nil?

  add_query_hash(hash)
end