matches



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.

Syntax

matches(value, regExp)

ArgumentTypeDescription
valueString or IntegerValue
regExpRegular ExpressionA regular expression, or a list of regular expressions.

Examples

 matches(in.code, "^[AB].*") 

matches() returns 1 if in.code starts with either 'A' or 'B', and 0 otherwise.


matches(in.line, "^([^,]*[,]){67}[^,]*$") 

Matches a string containing 68 values separated by commas - useful, for example, when filtering for valid lines from an input csv file.


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".

See Also