regex.extract

regex.extract(string, expression [, substitution] [, no_match])

Returns the result of extracting the regular expression from the string, optionally with a substitution expression and a specified result if no match is found. Returns an empty string, or the string specified in no_match if the expression does not match. If the string specified was none, an empty string is returned.

no_match was introduced in BMC Atrium Discovery 8.3.

The optional substitution expression is used to store groups that match the search expression. The first group is stored in \1, the second in \2, and so forth. For example:

// Extract the version using group 1 of the regular expression.
version := regex.extract(process.cmd, path_regex, raw "\1", no_match := 'No match.');

A versioning string is of the form "Version 2.7.182 patch 69". To extract the patch number, the following function is used:

patch := regex.extract(cmdResult.result, regex 'patch (\d+)',
                          raw '\1', no_match := 'Unsupported.');

The expression patch (\d+) matches patch 69 in the versioning string and it contains the first group matching \1 which is 69. If the versioning string was "Version 2.7.182 patch 69 patch 70" then the second group matching \2 is 70.

If the versioning string was "Version 2.7.182", the function would return "Unsupported."

Examples of its use are shown in How to Model your Business Applications.

Was this page helpful? Yes No Submitting... Thank you

Comments