Creates a regular expression.
The pattern function uses the Java Pattern class to define a regular expression. The pattern function can include a test value for evaluation or can be used in conjunction with the filter and index functions. The optional second parameter specifies the flags defined by the Java Pattern class. The optional third parameter specifies a test value.
The following criteria expression always returns true. (The second parameter in the following example—the number 2—is a flag for the Java Pattern class that indicates case-insensitivity. Do not confuse this flag with the use of the number 2 in most of the other criteria expression functions, which would indicate a third item.)
pattern("Chris .*", 2, "chris Smith")
The following are examples of regular expressions you can use with the pattern function. The value for the second parameter has meaning but is not required.
pattern("Candy.*", 2, "CandyBar") // starts with pattern("^(?!Bar).*", 2, " CandyBar ") // not starts with pattern(".*Bar", 2, " CandyBar ") // ends with pattern("^(?!.*Candy$).*", 2, " CandyBar ") // not ends with pattern(".*Candy.*", 2, " CandyBar ") // contains pattern("^((?!cb).)*", 2, " CandyBar ") // not contains
The following criteria expression returns true if the cart complex attribute category includes a product attribute with a value that ends with Truck.
count( filter( get("Account.cart"), "product", pattern(".*Truck") ) ) != 0