every

Table of Contents

Prototype: every(regex, list)

Return type: boolean

Description: Returns whether every element in the variable list matches the unanchored regex.

Arguments:

  • regex : Regular expression to find, in the range .*

  • list : The name of the list variable to check, in the range [a-zA-Z0-9_$(){}\[\].:]+. It can be a data container or a regular list.

Example:

body common control
{
      bundlesequence => { "test" };
}

bundle agent test

{
  classes:
      "every_dot_star" expression => every(".*", test);
      "every_dot" expression => every(".", test);
      "every_number" expression => every("[0-9]", test);

      "every2_dot_star" expression => every(".*", test2);
      "every2_dot" expression => every(".", test2);
      "every2_number" expression => every("[0-9]", test2);

  vars:
      "test" slist => {
                        1,2,3,
                        "one", "two", "three",
                        "long string",
                        "four", "fix", "six",
                        "one", "two", "three",
      };

      "test2" data => parsejson('[1,2,3,
                        "one", "two", "three",
                        "long string",
                        "four", "fix", "six",
                        "one", "two", "three",]');

  reports:
      "The test list is $(test)";

    every_dot_star::
      "every() test passed: every element matches '.*'";
    !every_dot_star::
      "every() test failed: not every element matches '.*'";
    every_number::
      "every() test failed: every element matches '[0-9]'";
    !every_number::
      "every() test passed: not every element matches '[0-9]'";
    every_dot::
      "every() test failed: every element matches '.'";
    !every_dot::
      "every() test passed: not every element matches '.'";

      "The test2 list is $(test2)";
    every2_dot_star::
      "every() test2 passed: every element matches '.*'";
    !every2_dot_star::
      "every() test2 failed: not every element matches '.*'";
    every2_number::
      "every() test2 failed: every element matches '[0-9]'";
    !every2_number::
      "every() test2 passed: not every element matches '[0-9]'";
    every2_dot::
      "every() test2 failed: every element matches '.'";
    !every2_dot::
      "every() test2 passed: not every element matches '.'";
}

Output:

R: The test list is 1
R: The test list is 2
R: The test list is 3
R: The test list is one
R: The test list is two
R: The test list is three
R: The test list is long string
R: The test list is four
R: The test list is fix
R: The test list is six
R: every() test passed: every element matches '.*'
R: every() test passed: not every element matches '[0-9]'
R: every() test passed: not every element matches '.'
R: The test2 list is 1
R: The test2 list is 2
R: The test2 list is 3
R: The test2 list is one
R: The test2 list is two
R: The test2 list is three
R: The test2 list is long string
R: The test2 list is four
R: The test2 list is fix
R: The test2 list is six
R: every() test2 passed: every element matches '.*'
R: every() test2 passed: not every element matches '[0-9]'
R: every() test2 passed: not every element matches '.'

See also: filter(), some(), and none().