Skip to main content

Inner functions

It is possible to use the following inner functions within other ContexQL functions that use String arguments, to enhance the flexibility of the queries with pattern matching functionality:

  1. regex(pattern)

    • The function checks whether a match of a POSIX regular expression pattern occurs within a string.
    • In case a specific location in a string is needed, metacharacters ^ and $ can be used to bind to start and end of the string respectively.
    • Allows complex pattern matching based on regular expression syntax.
    • Example: @has_symbol(regex("MAX"))
      • This matches all objects that contain a symbol with a MAX substring in its name.
    tip

    This function can also be used to check the length of a string metadata entry. For example, the following code will check if the entry is at least 150 characters long:

    @match_object_meta($some_meta regex("^.{150,}$"))

    The upper limit of a bound in POSIX regex is 255, therefore if you need to enforce longer strings you need to repeat the matching block or multiply it.

  2. iregex(pattern)

    • A case-insensitive version of regex.
    • Performs matching without regard to case differences.
    • Example: @has_name(iregex("\\.exe$"))
      • This matches all objects that have names ending with .exe, regardless of letter casing.
  3. starts_with(prefix)

    • Matches values that start with the specified string prefix.
    • Useful for straightforward, prefix-based matching without the complexity of regular expressions.
    • Example:
      @match_object_meta($properties.application starts_with("Microsoft"))
      • This matches objects that have a $properties.application metadata key, and its value begins with Microsoft.