Excerpt | ||
---|---|---|
| ||
matches(value, regExp) Tests whether a value matches a regular expression. |
Function: matches()
Tests whether a value matches a regular expression or a list of regular expressions. If a list of regular expressions is supplied, the index in that list for the first matching regular expression is returned; if no matches are found, the function returns 0.
...
matches(in.code, "^[AB].*")
matches() returns 1 if in.code starts with either 'A' or 'B', and 0 otherwise.
...
getElement(["Passed","Pending","Failed"],matches(in.code, ["^[AB].*", "^[CD].*", "^[EF].*"]),"Holding")
Translates in.code, which contains a text code for the status of a product, to a useful description.
matches() is used to determine whether in.code starts with: A or B for "Passed"; C or D for "Pending"; E or F for "Failed". If in.code does not match any of these, it is assigned the description "Holding".
The function returns the index in the list of the expression matched. So if in.code is equal to 'A33567', matches() returns 1 since the first expression in the list is matched. This is then passed to getElement, which finds the value in its list at index 1, which is "Passed".
Similarly, if the value of in.code is 'Z33567', matches() returns 0, since no values in the list of expressions match. This is resolved by getElement to the default value, "Holding".
...